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

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

    ForceChoice 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 ForceChoice.  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_MIRT_namespace {
using stan::model::model_base_crtp;
using namespace stan::math;
stan::math::profile_map profiles__;
static constexpr std::array<const char*, 148> locations_array__ =
  {" (found before start of program)",
  " (in 'string', line 40, column 2 to column 38)",
  " (in 'string', line 41, column 2 to column 33)",
  " (in 'string', line 42, column 2 to column 46)",
  " (in 'string', line 43, column 2 to column 46)",
  " (in 'string', line 44, column 2 to column 45)",
  " (in 'string', line 45, column 2 to column 31)",
  " (in 'string', line 48, column 2 to column 17)",
  " (in 'string', line 49, column 2 to column 21)",
  " (in 'string', line 50, column 2 to column 20)",
  " (in 'string', line 51, column 2 to column 18)",
  " (in 'string', line 127, column 2 to column 20)",
  " (in 'string', line 128, column 2 to column 24)",
  " (in 'string', line 61, column 6 to column 18)",
  " (in 'string', line 68, column 12 to column 26)",
  " (in 'string', line 67, column 17 to line 69, column 11)",
  " (in 'string', line 65, column 12 to column 34)",
  " (in 'string', line 66, column 12 to column 21)",
  " (in 'string', line 64, column 35 to line 67, column 11)",
  " (in 'string', line 64, column 10 to line 69, column 11)",
  " (in 'string', line 63, column 23 to line 70, column 9)",
  " (in 'string', line 63, column 8 to line 70, column 9)",
  " (in 'string', line 62, column 21 to line 71, column 7)",
  " (in 'string', line 62, column 6 to line 71, column 7)",
  " (in 'string', line 60, column 4 to line 72, column 5)",
  " (in 'string', line 59, column 9 to line 73, column 3)",
  " (in 'string', line 56, column 8 to column 22)",
  " (in 'string', line 55, column 21 to line 57, column 7)",
  " (in 'string', line 55, column 6 to line 57, column 7)",
  " (in 'string', line 54, column 19 to line 58, column 5)",
  " (in 'string', line 54, column 4 to line 58, column 5)",
  " (in 'string', line 53, column 23 to line 59, column 3)",
  " (in 'string', line 53, column 2 to line 73, column 3)",
  " (in 'string', line 79, column 6 to column 50)",
  " (in 'string', line 78, column 11 to line 80, column 5)",
  " (in 'string', line 77, column 6 to column 53)",
  " (in 'string', line 76, column 15 to line 78, column 5)",
  " (in 'string', line 76, column 4 to line 80, column 5)",
  " (in 'string', line 75, column 17 to line 81, column 3)",
  " (in 'string', line 75, column 2 to line 81, column 3)",
  " (in 'string', line 84, column 4 to column 63)",
  " (in 'string', line 83, column 21 to line 85, column 3)",
  " (in 'string', line 83, column 2 to line 85, column 3)",
  " (in 'string', line 99, column 6 to column 63)",
  " (in 'string', line 98, column 23 to line 100, column 5)",
  " (in 'string', line 98, column 4 to line 100, column 5)",
  " (in 'string', line 97, column 9 to line 101, column 3)",
  " (in 'string', line 94, column 6 to column 75)",
  " (in 'string', line 95, column 6 to column 51)",
  " (in 'string', line 93, column 23 to line 96, column 5)",
  " (in 'string', line 93, column 4 to line 96, column 5)",
  " (in 'string', line 92, column 30 to line 97, column 3)",
  " (in 'string', line 92, column 9 to line 101, column 3)",
  " (in 'string', line 89, column 6 to column 69)",
  " (in 'string', line 90, column 6 to column 51)",
  " (in 'string', line 88, column 23 to line 91, column 5)",
  " (in 'string', line 88, column 4 to line 91, column 5)",
  " (in 'string', line 87, column 23 to line 92, column 3)",
  " (in 'string', line 87, column 2 to line 101, column 3)",
  " (in 'string', line 132, column 4 to column 21)",
  " (in 'string', line 131, column 9 to line 133, column 3)",
  " (in 'string', line 130, column 4 to column 53)",
  " (in 'string', line 129, column 13 to line 131, column 3)",
  " (in 'string', line 129, column 2 to line 133, column 3)",
  " (in 'string', line 138, column 6 to column 47)",
  " (in 'string', line 137, column 11 to line 139, column 5)",
  " (in 'string', line 136, column 6 to column 55)",
  " (in 'string', line 135, column 25 to line 137, column 5)",
  " (in 'string', line 135, column 4 to line 139, column 5)",
  " (in 'string', line 134, column 21 to line 140, column 3)",
  " (in 'string', line 134, column 2 to line 140, column 3)",
  " (in 'string', line 105, column 4 to column 38)",
  " (in 'string', line 104, column 23 to line 106, column 3)",
  " (in 'string', line 104, column 2 to line 106, column 3)",
  " (in 'string', line 107, column 2 to column 28)",
  " (in 'string', line 109, column 4 to column 31)",
  " (in 'string', line 108, column 23 to line 110, column 3)",
  " (in 'string', line 108, column 2 to line 110, column 3)",
  " (in 'string', line 112, column 4 to column 31)",
  " (in 'string', line 111, column 23 to line 113, column 3)",
  " (in 'string', line 111, column 2 to line 113, column 3)",
  " (in 'string', line 115, column 4 to column 34)",
  " (in 'string', line 114, column 13 to line 116, column 3)",
  " (in 'string', line 114, column 2 to line 116, column 3)",
  " (in 'string', line 118, column 4 to column 32)",
  " (in 'string', line 117, column 17 to line 119, column 3)",
  " (in 'string', line 117, column 2 to line 119, column 3)",
  " (in 'string', line 123, column 4 to column 21)",
  " (in 'string', line 122, column 9 to line 124, column 3)",
  " (in 'string', line 121, column 4 to column 29)",
  " (in 'string', line 120, column 23 to line 122, column 3)",
  " (in 'string', line 120, column 2 to line 124, column 3)",
  " (in 'string', line 4, column 2 to column 21)",
  " (in 'string', line 5, column 2 to column 17)",
  " (in 'string', line 6, column 2 to column 17)",
  " (in 'string', line 7, column 2 to column 17)",
  " (in 'string', line 8, column 2 to column 35)",
  " (in 'string', line 9, column 8 to column 13)",
  " (in 'string', line 9, column 2 to column 39)",
  " (in 'string', line 10, column 8 to column 13)",
  " (in 'string', line 10, column 2 to column 41)",
  " (in 'string', line 11, column 8 to column 13)",
  " (in 'string', line 11, column 2 to column 41)",
  " (in 'string', line 12, column 9 to column 10)",
  " (in 'string', line 12, column 12 to column 13)",
  " (in 'string', line 12, column 2 to column 24)",
  " (in 'string', line 13, column 2 to column 12)",
  " (in 'string', line 14, column 2 to column 24)",
  " (in 'string', line 15, column 2 to column 12)",
  " (in 'string', line 16, column 2 to column 24)",
  " (in 'string', line 17, column 2 to column 12)",
  " (in 'string', line 18, column 2 to column 24)",
  " (in 'string', line 19, column 2 to column 12)",
  " (in 'string', line 20, column 2 to column 24)",
  " (in 'string', line 21, column 9 to column 10)",
  " (in 'string', line 21, column 2 to column 21)",
  " (in 'string', line 24, column 2 to column 22)",
  " (in 'string', line 25, column 2 to column 17)",
  " (in 'string', line 26, column 2 to column 17)",
  " (in 'string', line 31, column 10 to column 27)",
  " (in 'string', line 30, column 33 to line 32, column 9)",
  " (in 'string', line 30, column 8 to line 32, column 9)",
  " (in 'string', line 29, column 21 to line 33, column 7)",
  " (in 'string', line 29, column 6 to line 33, column 7)",
  " (in 'string', line 28, column 19 to line 34, column 5)",
  " (in 'string', line 28, column 4 to line 34, column 5)",
  " (in 'string', line 27, column 23 to line 35, column 3)",
  " (in 'string', line 27, column 2 to line 35, column 3)",
  " (in 'string', line 36, column 23 to column 34)",
  " (in 'string', line 36, column 2 to column 34)",
  " (in 'string', line 37, column 23 to column 34)",
  " (in 'string', line 37, column 2 to column 34)",
  " (in 'string', line 40, column 18 to column 29)",
  " (in 'string', line 41, column 28 to column 29)",
  " (in 'string', line 42, column 36 to column 42)",
  " (in 'string', line 43, column 36 to column 42)",
  " (in 'string', line 44, column 23 to column 36)",
  " (in 'string', line 45, column 8 to column 9)",
  " (in 'string', line 45, column 18 to column 19)",
  " (in 'string', line 48, column 9 to column 10)",
  " (in 'string', line 48, column 12 to column 13)",
  " (in 'string', line 49, column 9 to column 10)",
  " (in 'string', line 49, column 12 to column 13)",
  " (in 'string', line 50, column 9 to column 14)",
  " (in 'string', line 51, column 9 to column 14)",
  " (in 'string', line 127, column 9 to column 10)",
  " (in 'string', line 127, column 12 to column 13)",
  " (in 'string', line 128, column 9 to column 14)"};
#include <stan_meta_header.hpp>
class model_MIRT final : public model_base_crtp<model_MIRT> {
private:
  int N_obs;
  int N;
  int I;
  int D;
  int model_type;
  std::vector<int> y;
  std::vector<int> pid;
  std::vector<int> iid;
  Eigen::Matrix<double,-1,-1> Q_matrix_data__;
  double a_mu;
  double a_sigma;
  double b_mu;
  double b_sigma;
  double c_mu;
  double c_sigma;
  double d_mu;
  double d_sigma;
  Eigen::Matrix<double,-1,1> theta_mu_data__;
  int a_free_size;
  int c_size;
  int d_size;
  int L_Corr_1dim__;
  int L_Corr_2dim__;
  Eigen::Map<Eigen::Matrix<double,-1,-1>> Q_matrix{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> theta_mu{nullptr, 0};
public:
  ~model_MIRT() {}
  model_MIRT(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_MIRT_namespace::model_MIRT";
    // 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__ = 92;
      context__.validate_dims("data initialization", "N_obs", "int",
        std::vector<size_t>{});
      N_obs = std::numeric_limits<int>::min();
      current_statement__ = 92;
      N_obs = context__.vals_i("N_obs")[(1 - 1)];
      current_statement__ = 92;
      stan::math::check_greater_or_equal(function__, "N_obs", N_obs, 1);
      current_statement__ = 93;
      context__.validate_dims("data initialization", "N", "int",
        std::vector<size_t>{});
      N = std::numeric_limits<int>::min();
      current_statement__ = 93;
      N = context__.vals_i("N")[(1 - 1)];
      current_statement__ = 93;
      stan::math::check_greater_or_equal(function__, "N", N, 1);
      current_statement__ = 94;
      context__.validate_dims("data initialization", "I", "int",
        std::vector<size_t>{});
      I = std::numeric_limits<int>::min();
      current_statement__ = 94;
      I = context__.vals_i("I")[(1 - 1)];
      current_statement__ = 94;
      stan::math::check_greater_or_equal(function__, "I", I, 1);
      current_statement__ = 95;
      context__.validate_dims("data initialization", "D", "int",
        std::vector<size_t>{});
      D = std::numeric_limits<int>::min();
      current_statement__ = 95;
      D = context__.vals_i("D")[(1 - 1)];
      current_statement__ = 95;
      stan::math::check_greater_or_equal(function__, "D", D, 1);
      current_statement__ = 96;
      context__.validate_dims("data initialization", "model_type", "int",
        std::vector<size_t>{});
      model_type = std::numeric_limits<int>::min();
      current_statement__ = 96;
      model_type = context__.vals_i("model_type")[(1 - 1)];
      current_statement__ = 96;
      stan::math::check_greater_or_equal(function__, "model_type",
        model_type, 1);
      current_statement__ = 96;
      stan::math::check_less_or_equal(function__, "model_type", model_type, 4);
      current_statement__ = 97;
      stan::math::validate_non_negative_index("y", "N_obs", N_obs);
      current_statement__ = 98;
      context__.validate_dims("data initialization", "y", "int",
        std::vector<size_t>{static_cast<size_t>(N_obs)});
      y = std::vector<int>(N_obs, std::numeric_limits<int>::min());
      current_statement__ = 98;
      y = context__.vals_i("y");
      current_statement__ = 98;
      stan::math::check_greater_or_equal(function__, "y", y, 0);
      current_statement__ = 98;
      stan::math::check_less_or_equal(function__, "y", y, 1);
      current_statement__ = 99;
      stan::math::validate_non_negative_index("pid", "N_obs", N_obs);
      current_statement__ = 100;
      context__.validate_dims("data initialization", "pid", "int",
        std::vector<size_t>{static_cast<size_t>(N_obs)});
      pid = std::vector<int>(N_obs, std::numeric_limits<int>::min());
      current_statement__ = 100;
      pid = context__.vals_i("pid");
      current_statement__ = 100;
      stan::math::check_greater_or_equal(function__, "pid", pid, 1);
      current_statement__ = 100;
      stan::math::check_less_or_equal(function__, "pid", pid, N);
      current_statement__ = 101;
      stan::math::validate_non_negative_index("iid", "N_obs", N_obs);
      current_statement__ = 102;
      context__.validate_dims("data initialization", "iid", "int",
        std::vector<size_t>{static_cast<size_t>(N_obs)});
      iid = std::vector<int>(N_obs, std::numeric_limits<int>::min());
      current_statement__ = 102;
      iid = context__.vals_i("iid");
      current_statement__ = 102;
      stan::math::check_greater_or_equal(function__, "iid", iid, 1);
      current_statement__ = 102;
      stan::math::check_less_or_equal(function__, "iid", iid, I);
      current_statement__ = 103;
      stan::math::validate_non_negative_index("Q_matrix", "I", I);
      current_statement__ = 104;
      stan::math::validate_non_negative_index("Q_matrix", "D", D);
      current_statement__ = 105;
      context__.validate_dims("data initialization", "Q_matrix", "double",
        std::vector<size_t>{static_cast<size_t>(I), static_cast<size_t>(D)});
      Q_matrix_data__ = Eigen::Matrix<double,-1,-1>::Constant(I, D,
                          std::numeric_limits<double>::quiet_NaN());
      new (&Q_matrix)
        Eigen::Map<Eigen::Matrix<double,-1,-1>>(Q_matrix_data__.data(), I, D);
      {
        std::vector<local_scalar_t__> Q_matrix_flat__;
        current_statement__ = 105;
        Q_matrix_flat__ = context__.vals_r("Q_matrix");
        current_statement__ = 105;
        pos__ = 1;
        current_statement__ = 105;
        for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
          current_statement__ = 105;
          for (int sym2__ = 1; sym2__ <= I; ++sym2__) {
            current_statement__ = 105;
            stan::model::assign(Q_matrix, Q_matrix_flat__[(pos__ - 1)],
              "assigning variable Q_matrix", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 105;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 106;
      context__.validate_dims("data initialization", "a_mu", "double",
        std::vector<size_t>{});
      a_mu = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 106;
      a_mu = context__.vals_r("a_mu")[(1 - 1)];
      current_statement__ = 107;
      context__.validate_dims("data initialization", "a_sigma", "double",
        std::vector<size_t>{});
      a_sigma = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 107;
      a_sigma = context__.vals_r("a_sigma")[(1 - 1)];
      current_statement__ = 107;
      stan::math::check_greater_or_equal(function__, "a_sigma", a_sigma, 0);
      current_statement__ = 108;
      context__.validate_dims("data initialization", "b_mu", "double",
        std::vector<size_t>{});
      b_mu = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 108;
      b_mu = context__.vals_r("b_mu")[(1 - 1)];
      current_statement__ = 109;
      context__.validate_dims("data initialization", "b_sigma", "double",
        std::vector<size_t>{});
      b_sigma = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 109;
      b_sigma = context__.vals_r("b_sigma")[(1 - 1)];
      current_statement__ = 109;
      stan::math::check_greater_or_equal(function__, "b_sigma", b_sigma, 0);
      current_statement__ = 110;
      context__.validate_dims("data initialization", "c_mu", "double",
        std::vector<size_t>{});
      c_mu = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 110;
      c_mu = context__.vals_r("c_mu")[(1 - 1)];
      current_statement__ = 111;
      context__.validate_dims("data initialization", "c_sigma", "double",
        std::vector<size_t>{});
      c_sigma = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 111;
      c_sigma = context__.vals_r("c_sigma")[(1 - 1)];
      current_statement__ = 111;
      stan::math::check_greater_or_equal(function__, "c_sigma", c_sigma, 0);
      current_statement__ = 112;
      context__.validate_dims("data initialization", "d_mu", "double",
        std::vector<size_t>{});
      d_mu = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 112;
      d_mu = context__.vals_r("d_mu")[(1 - 1)];
      current_statement__ = 113;
      context__.validate_dims("data initialization", "d_sigma", "double",
        std::vector<size_t>{});
      d_sigma = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 113;
      d_sigma = context__.vals_r("d_sigma")[(1 - 1)];
      current_statement__ = 113;
      stan::math::check_greater_or_equal(function__, "d_sigma", d_sigma, 0);
      current_statement__ = 114;
      stan::math::validate_non_negative_index("theta_mu", "D", D);
      current_statement__ = 115;
      context__.validate_dims("data initialization", "theta_mu", "double",
        std::vector<size_t>{static_cast<size_t>(D)});
      theta_mu_data__ = Eigen::Matrix<double,-1,1>::Constant(D,
                          std::numeric_limits<double>::quiet_NaN());
      new (&theta_mu)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(theta_mu_data__.data(), D);
      {
        std::vector<local_scalar_t__> theta_mu_flat__;
        current_statement__ = 115;
        theta_mu_flat__ = context__.vals_r("theta_mu");
        current_statement__ = 115;
        pos__ = 1;
        current_statement__ = 115;
        for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
          current_statement__ = 115;
          stan::model::assign(theta_mu, theta_mu_flat__[(pos__ - 1)],
            "assigning variable theta_mu", stan::model::index_uni(sym1__));
          current_statement__ = 115;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 116;
      a_free_size = std::numeric_limits<int>::min();
      current_statement__ = 116;
      a_free_size = 0;
      current_statement__ = 117;
      c_size = std::numeric_limits<int>::min();
      current_statement__ = 117;
      c_size = 0;
      current_statement__ = 118;
      d_size = std::numeric_limits<int>::min();
      current_statement__ = 118;
      d_size = 0;
      current_statement__ = 127;
      if (stan::math::logical_gte(model_type, 2)) {
        current_statement__ = 125;
        for (int i = 1; i <= I; ++i) {
          current_statement__ = 123;
          for (int j = 1; j <= D; ++j) {
            current_statement__ = 121;
            if (stan::math::logical_eq(
                  stan::model::rvalue(Q_matrix, "Q_matrix",
                    stan::model::index_uni(i), stan::model::index_uni(j)), 1)) {
              current_statement__ = 119;
              a_free_size = (a_free_size + 1);
            }
          }
        }
      }
      current_statement__ = 129;
      if (stan::math::logical_gte(model_type, 3)) {
        current_statement__ = 128;
        c_size = I;
      }
      current_statement__ = 131;
      if (stan::math::logical_eq(model_type, 4)) {
        current_statement__ = 130;
        d_size = I;
      }
      current_statement__ = 132;
      stan::math::validate_non_negative_index("a_free", "a_free_size",
        a_free_size);
      current_statement__ = 133;
      stan::math::validate_non_negative_index("b", "I", I);
      current_statement__ = 134;
      stan::math::validate_non_negative_index("c", "c_size", c_size);
      current_statement__ = 135;
      stan::math::validate_non_negative_index("d", "d_size", d_size);
      current_statement__ = 136;
      L_Corr_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 136;
      L_Corr_1dim__ = (stan::math::logical_gt(D, 1) ? D : 2);
      current_statement__ = 136;
      stan::math::validate_non_negative_index("L_Corr", "D > 1 ? D : 2",
        L_Corr_1dim__);
      current_statement__ = 136;
      L_Corr_2dim__ = std::numeric_limits<int>::min();
      current_statement__ = 136;
      L_Corr_2dim__ = (stan::math::logical_gt(D, 1) ? D : 2);
      current_statement__ = 136;
      stan::math::validate_non_negative_index("L_Corr", "D > 1 ? D : 2",
        L_Corr_2dim__);
      current_statement__ = 137;
      stan::math::validate_non_negative_index("theta_raw", "N", N);
      current_statement__ = 138;
      stan::math::validate_non_negative_index("theta_raw", "D", D);
      current_statement__ = 139;
      stan::math::validate_non_negative_index("a", "I", I);
      current_statement__ = 140;
      stan::math::validate_non_negative_index("a", "D", D);
      current_statement__ = 141;
      stan::math::validate_non_negative_index("theta", "N", N);
      current_statement__ = 142;
      stan::math::validate_non_negative_index("theta", "D", D);
      current_statement__ = 143;
      stan::math::validate_non_negative_index("eta", "N_obs", N_obs);
      current_statement__ = 144;
      stan::math::validate_non_negative_index("p", "N_obs", N_obs);
      current_statement__ = 145;
      stan::math::validate_non_negative_index("Corr", "D", D);
      current_statement__ = 146;
      stan::math::validate_non_negative_index("Corr", "D", D);
      current_statement__ = 147;
      stan::math::validate_non_negative_index("log_lik", "N_obs", N_obs);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
    num_params_r__ = a_free_size + I + c_size + d_size + ((L_Corr_1dim__ *
      (L_Corr_1dim__ - 1)) / 2) + (N * D);
  }
  inline std::string model_name() const final {
    return "model_MIRT";
  }
  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_MIRT_namespace::log_prob";
    // suppress unused var warning
    (void) function__;
    try {
      Eigen::Matrix<local_scalar_t__,-1,1> a_free =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(a_free_size,
          DUMMY_VAR__);
      current_statement__ = 1;
      a_free = in__.template read_constrain_lb<
                 Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(0, lp__,
                 a_free_size);
      Eigen::Matrix<local_scalar_t__,-1,1> b =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(I, DUMMY_VAR__);
      current_statement__ = 2;
      b = in__.template read_constrain_lub<
            Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(-4, 4, lp__, I);
      Eigen::Matrix<local_scalar_t__,-1,1> c =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(c_size, DUMMY_VAR__);
      current_statement__ = 3;
      c = in__.template read_constrain_lub<
            Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(c_mu, c_sigma,
            lp__, c_size);
      Eigen::Matrix<local_scalar_t__,-1,1> d =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(d_size, DUMMY_VAR__);
      current_statement__ = 4;
      d = in__.template read_constrain_lub<
            Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(d_mu, d_sigma,
            lp__, d_size);
      Eigen::Matrix<local_scalar_t__,-1,-1> L_Corr =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(L_Corr_1dim__,
          L_Corr_2dim__, DUMMY_VAR__);
      current_statement__ = 5;
      L_Corr = in__.template read_constrain_cholesky_factor_corr<
                 Eigen::Matrix<local_scalar_t__,-1,-1>, jacobian__>(lp__,
                 L_Corr_2dim__);
      std::vector<Eigen::Matrix<local_scalar_t__,-1,1>> theta_raw =
        std::vector<Eigen::Matrix<local_scalar_t__,-1,1>>(N,
          Eigen::Matrix<local_scalar_t__,-1,1>::Constant(D, DUMMY_VAR__));
      current_statement__ = 6;
      theta_raw = in__.template read<
                    std::vector<Eigen::Matrix<local_scalar_t__,-1,1>>>(N, D);
      Eigen::Matrix<local_scalar_t__,-1,-1> a =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(I, D, DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,-1> theta =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(N, D, DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> eta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_obs, DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> p =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_obs, DUMMY_VAR__);
      current_statement__ = 32;
      if (stan::math::logical_eq(model_type, 1)) {
        current_statement__ = 30;
        for (int i = 1; i <= I; ++i) {
          current_statement__ = 28;
          for (int j = 1; j <= D; ++j) {
            current_statement__ = 26;
            stan::model::assign(a, 1.0, "assigning variable a",
              stan::model::index_uni(i), stan::model::index_uni(j));
          }
        }
      } else {
        int idx = std::numeric_limits<int>::min();
        current_statement__ = 13;
        idx = 1;
        current_statement__ = 23;
        for (int i = 1; i <= I; ++i) {
          current_statement__ = 21;
          for (int j = 1; j <= D; ++j) {
            current_statement__ = 19;
            if (stan::math::logical_eq(
                  stan::model::rvalue(Q_matrix, "Q_matrix",
                    stan::model::index_uni(i), stan::model::index_uni(j)), 1)) {
              current_statement__ = 16;
              stan::model::assign(a,
                stan::model::rvalue(a_free, "a_free",
                  stan::model::index_uni(idx)), "assigning variable a",
                stan::model::index_uni(i), stan::model::index_uni(j));
              current_statement__ = 17;
              idx = (idx + 1);
            } else {
              current_statement__ = 14;
              stan::model::assign(a, 0.0, "assigning variable a",
                stan::model::index_uni(i), stan::model::index_uni(j));
            }
          }
        }
      }
      current_statement__ = 39;
      for (int n = 1; n <= N; ++n) {
        current_statement__ = 37;
        if (stan::math::logical_gt(D, 1)) {
          current_statement__ = 35;
          stan::model::assign(theta,
            stan::math::transpose(
              stan::math::add(theta_mu,
                stan::math::multiply(L_Corr,
                  stan::model::rvalue(theta_raw, "theta_raw",
                    stan::model::index_uni(n))))),
            "assigning variable theta", stan::model::index_uni(n));
        } else {
          current_statement__ = 33;
          stan::model::assign(theta,
            (stan::model::rvalue(theta_mu, "theta_mu",
               stan::model::index_uni(1)) +
            stan::model::rvalue(
              stan::model::rvalue(theta_raw, "theta_raw",
                stan::model::index_uni(n)), "theta_raw[n]",
              stan::model::index_uni(1))), "assigning variable theta",
            stan::model::index_uni(n), stan::model::index_uni(1));
        }
      }
      current_statement__ = 42;
      for (int n = 1; n <= N_obs; ++n) {
        current_statement__ = 40;
        stan::model::assign(eta,
          (stan::math::dot_product(
             stan::model::rvalue(theta, "theta",
               stan::model::index_uni(
                 stan::model::rvalue(pid, "pid", stan::model::index_uni(n)))),
             stan::model::rvalue(a, "a",
               stan::model::index_uni(
                 stan::model::rvalue(iid, "iid", stan::model::index_uni(n)))))
          -
          stan::model::rvalue(b, "b",
            stan::model::index_uni(
              stan::model::rvalue(iid, "iid", stan::model::index_uni(n))))),
          "assigning variable eta", stan::model::index_uni(n));
      }
      current_statement__ = 58;
      if (stan::math::logical_eq(model_type, 3)) {
        current_statement__ = 56;
        for (int n = 1; n <= N_obs; ++n) {
          local_scalar_t__ p_raw = DUMMY_VAR__;
          current_statement__ = 53;
          p_raw = (stan::model::rvalue(c, "c",
                     stan::model::index_uni(
                       stan::model::rvalue(iid, "iid",
                         stan::model::index_uni(n))))
            + ((1.0 -
            stan::model::rvalue(c, "c",
              stan::model::index_uni(
                stan::model::rvalue(iid, "iid", stan::model::index_uni(n)))))
            *
            stan::math::inv_logit(
              stan::model::rvalue(eta, "eta", stan::model::index_uni(n)))));
          current_statement__ = 54;
          stan::model::assign(p,
            stan::math::fmin((1.0 - 1e-12), stan::math::fmax(1e-12, p_raw)),
            "assigning variable p", stan::model::index_uni(n));
        }
      } else {
        current_statement__ = 52;
        if (stan::math::logical_eq(model_type, 4)) {
          current_statement__ = 50;
          for (int n = 1; n <= N_obs; ++n) {
            local_scalar_t__ p_raw = DUMMY_VAR__;
            current_statement__ = 47;
            p_raw = (stan::model::rvalue(c, "c",
                       stan::model::index_uni(
                         stan::model::rvalue(iid, "iid",
                           stan::model::index_uni(n))))
              +
              ((stan::model::rvalue(d, "d",
                  stan::model::index_uni(
                    stan::model::rvalue(iid, "iid", stan::model::index_uni(n))))
              -
              stan::model::rvalue(c, "c",
                stan::model::index_uni(
                  stan::model::rvalue(iid, "iid", stan::model::index_uni(n)))))
              *
              stan::math::inv_logit(
                stan::model::rvalue(eta, "eta", stan::model::index_uni(n)))));
            current_statement__ = 48;
            stan::model::assign(p,
              stan::math::fmin((1.0 - 1e-12), stan::math::fmax(1e-12, p_raw)),
              "assigning variable p", stan::model::index_uni(n));
          }
        } else {
          current_statement__ = 45;
          for (int n = 1; n <= N_obs; ++n) {
            current_statement__ = 43;
            stan::model::assign(p,
              stan::math::fmin((1.0 - 1e-12),
                stan::math::fmax(1e-12,
                  stan::math::inv_logit(
                    stan::model::rvalue(eta, "eta", stan::model::index_uni(n))))),
              "assigning variable p", stan::model::index_uni(n));
          }
        }
      }
      {
        current_statement__ = 73;
        if (stan::math::logical_gte(model_type, 2)) {
          current_statement__ = 71;
          lp_accum__.add(stan::math::lognormal_lpdf<propto__>(a_free, a_mu,
                           a_sigma));
        }
        current_statement__ = 74;
        lp_accum__.add(stan::math::normal_lpdf<propto__>(b, b_mu, b_sigma));
        current_statement__ = 77;
        if (stan::math::logical_gte(model_type, 3)) {
          current_statement__ = 75;
          lp_accum__.add(stan::math::uniform_lpdf<propto__>(c, c_mu, c_sigma));
        }
        current_statement__ = 80;
        if (stan::math::logical_eq(model_type, 4)) {
          current_statement__ = 78;
          lp_accum__.add(stan::math::uniform_lpdf<propto__>(d, d_mu, d_sigma));
        }
        current_statement__ = 83;
        if (stan::math::logical_gt(D, 1)) {
          current_statement__ = 81;
          lp_accum__.add(stan::math::lkj_corr_cholesky_lpdf<propto__>(L_Corr,
                           1));
        }
        current_statement__ = 86;
        for (int n = 1; n <= N; ++n) {
          current_statement__ = 84;
          lp_accum__.add(stan::math::std_normal_lpdf<propto__>(
                           stan::model::rvalue(theta_raw, "theta_raw",
                             stan::model::index_uni(n))));
        }
        current_statement__ = 91;
        if (stan::math::logical_lte(model_type, 2)) {
          current_statement__ = 89;
          lp_accum__.add(stan::math::bernoulli_logit_lpmf<propto__>(y, eta));
        } else {
          current_statement__ = 87;
          lp_accum__.add(stan::math::bernoulli_lpmf<propto__>(y, p));
        }
      }
    } 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_MIRT_namespace::write_array";
    // suppress unused var warning
    (void) function__;
    try {
      Eigen::Matrix<double,-1,1> a_free =
        Eigen::Matrix<double,-1,1>::Constant(a_free_size,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 1;
      a_free = in__.template read_constrain_lb<
                 Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(0, lp__,
                 a_free_size);
      Eigen::Matrix<double,-1,1> b =
        Eigen::Matrix<double,-1,1>::Constant(I,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 2;
      b = in__.template read_constrain_lub<
            Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(-4, 4, lp__, I);
      Eigen::Matrix<double,-1,1> c =
        Eigen::Matrix<double,-1,1>::Constant(c_size,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 3;
      c = in__.template read_constrain_lub<
            Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(c_mu, c_sigma,
            lp__, c_size);
      Eigen::Matrix<double,-1,1> d =
        Eigen::Matrix<double,-1,1>::Constant(d_size,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 4;
      d = in__.template read_constrain_lub<
            Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(d_mu, d_sigma,
            lp__, d_size);
      Eigen::Matrix<double,-1,-1> L_Corr =
        Eigen::Matrix<double,-1,-1>::Constant(L_Corr_1dim__, L_Corr_2dim__,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 5;
      L_Corr = in__.template read_constrain_cholesky_factor_corr<
                 Eigen::Matrix<local_scalar_t__,-1,-1>, jacobian__>(lp__,
                 L_Corr_2dim__);
      std::vector<Eigen::Matrix<double,-1,1>> theta_raw =
        std::vector<Eigen::Matrix<double,-1,1>>(N,
          Eigen::Matrix<double,-1,1>::Constant(D,
            std::numeric_limits<double>::quiet_NaN()));
      current_statement__ = 6;
      theta_raw = in__.template read<
                    std::vector<Eigen::Matrix<local_scalar_t__,-1,1>>>(N, D);
      Eigen::Matrix<double,-1,-1> a =
        Eigen::Matrix<double,-1,-1>::Constant(I, D,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,-1> theta =
        Eigen::Matrix<double,-1,-1>::Constant(N, D,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> eta =
        Eigen::Matrix<double,-1,1>::Constant(N_obs,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> p =
        Eigen::Matrix<double,-1,1>::Constant(N_obs,
          std::numeric_limits<double>::quiet_NaN());
      out__.write(a_free);
      out__.write(b);
      out__.write(c);
      out__.write(d);
      out__.write(L_Corr);
      for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
          out__.write(theta_raw[(sym2__ - 1)][(sym1__ - 1)]);
        }
      }
      if (stan::math::logical_negation(
            (stan::math::primitive_value(emit_transformed_parameters__) ||
            stan::math::primitive_value(emit_generated_quantities__)))) {
        return ;
      }
      current_statement__ = 32;
      if (stan::math::logical_eq(model_type, 1)) {
        current_statement__ = 30;
        for (int i = 1; i <= I; ++i) {
          current_statement__ = 28;
          for (int j = 1; j <= D; ++j) {
            current_statement__ = 26;
            stan::model::assign(a, 1.0, "assigning variable a",
              stan::model::index_uni(i), stan::model::index_uni(j));
          }
        }
      } else {
        int idx = std::numeric_limits<int>::min();
        current_statement__ = 13;
        idx = 1;
        current_statement__ = 23;
        for (int i = 1; i <= I; ++i) {
          current_statement__ = 21;
          for (int j = 1; j <= D; ++j) {
            current_statement__ = 19;
            if (stan::math::logical_eq(
                  stan::model::rvalue(Q_matrix, "Q_matrix",
                    stan::model::index_uni(i), stan::model::index_uni(j)), 1)) {
              current_statement__ = 16;
              stan::model::assign(a,
                stan::model::rvalue(a_free, "a_free",
                  stan::model::index_uni(idx)), "assigning variable a",
                stan::model::index_uni(i), stan::model::index_uni(j));
              current_statement__ = 17;
              idx = (idx + 1);
            } else {
              current_statement__ = 14;
              stan::model::assign(a, 0.0, "assigning variable a",
                stan::model::index_uni(i), stan::model::index_uni(j));
            }
          }
        }
      }
      current_statement__ = 39;
      for (int n = 1; n <= N; ++n) {
        current_statement__ = 37;
        if (stan::math::logical_gt(D, 1)) {
          current_statement__ = 35;
          stan::model::assign(theta,
            stan::math::transpose(
              stan::math::add(theta_mu,
                stan::math::multiply(L_Corr,
                  stan::model::rvalue(theta_raw, "theta_raw",
                    stan::model::index_uni(n))))),
            "assigning variable theta", stan::model::index_uni(n));
        } else {
          current_statement__ = 33;
          stan::model::assign(theta,
            (stan::model::rvalue(theta_mu, "theta_mu",
               stan::model::index_uni(1)) +
            stan::model::rvalue(
              stan::model::rvalue(theta_raw, "theta_raw",
                stan::model::index_uni(n)), "theta_raw[n]",
              stan::model::index_uni(1))), "assigning variable theta",
            stan::model::index_uni(n), stan::model::index_uni(1));
        }
      }
      current_statement__ = 42;
      for (int n = 1; n <= N_obs; ++n) {
        current_statement__ = 40;
        stan::model::assign(eta,
          (stan::math::dot_product(
             stan::model::rvalue(theta, "theta",
               stan::model::index_uni(
                 stan::model::rvalue(pid, "pid", stan::model::index_uni(n)))),
             stan::model::rvalue(a, "a",
               stan::model::index_uni(
                 stan::model::rvalue(iid, "iid", stan::model::index_uni(n)))))
          -
          stan::model::rvalue(b, "b",
            stan::model::index_uni(
              stan::model::rvalue(iid, "iid", stan::model::index_uni(n))))),
          "assigning variable eta", stan::model::index_uni(n));
      }
      current_statement__ = 58;
      if (stan::math::logical_eq(model_type, 3)) {
        current_statement__ = 56;
        for (int n = 1; n <= N_obs; ++n) {
          double p_raw = std::numeric_limits<double>::quiet_NaN();
          current_statement__ = 53;
          p_raw = (stan::model::rvalue(c, "c",
                     stan::model::index_uni(
                       stan::model::rvalue(iid, "iid",
                         stan::model::index_uni(n))))
            + ((1.0 -
            stan::model::rvalue(c, "c",
              stan::model::index_uni(
                stan::model::rvalue(iid, "iid", stan::model::index_uni(n)))))
            *
            stan::math::inv_logit(
              stan::model::rvalue(eta, "eta", stan::model::index_uni(n)))));
          current_statement__ = 54;
          stan::model::assign(p,
            stan::math::fmin((1.0 - 1e-12), stan::math::fmax(1e-12, p_raw)),
            "assigning variable p", stan::model::index_uni(n));
        }
      } else {
        current_statement__ = 52;
        if (stan::math::logical_eq(model_type, 4)) {
          current_statement__ = 50;
          for (int n = 1; n <= N_obs; ++n) {
            double p_raw = std::numeric_limits<double>::quiet_NaN();
            current_statement__ = 47;
            p_raw = (stan::model::rvalue(c, "c",
                       stan::model::index_uni(
                         stan::model::rvalue(iid, "iid",
                           stan::model::index_uni(n))))
              +
              ((stan::model::rvalue(d, "d",
                  stan::model::index_uni(
                    stan::model::rvalue(iid, "iid", stan::model::index_uni(n))))
              -
              stan::model::rvalue(c, "c",
                stan::model::index_uni(
                  stan::model::rvalue(iid, "iid", stan::model::index_uni(n)))))
              *
              stan::math::inv_logit(
                stan::model::rvalue(eta, "eta", stan::model::index_uni(n)))));
            current_statement__ = 48;
            stan::model::assign(p,
              stan::math::fmin((1.0 - 1e-12), stan::math::fmax(1e-12, p_raw)),
              "assigning variable p", stan::model::index_uni(n));
          }
        } else {
          current_statement__ = 45;
          for (int n = 1; n <= N_obs; ++n) {
            current_statement__ = 43;
            stan::model::assign(p,
              stan::math::fmin((1.0 - 1e-12),
                stan::math::fmax(1e-12,
                  stan::math::inv_logit(
                    stan::model::rvalue(eta, "eta", stan::model::index_uni(n))))),
              "assigning variable p", stan::model::index_uni(n));
          }
        }
      }
      if (emit_transformed_parameters__) {
        out__.write(a);
        out__.write(theta);
        out__.write(eta);
        out__.write(p);
      }
      if (stan::math::logical_negation(emit_generated_quantities__)) {
        return ;
      }
      Eigen::Matrix<double,-1,-1> Corr =
        Eigen::Matrix<double,-1,-1>::Constant(D, D,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> log_lik =
        Eigen::Matrix<double,-1,1>::Constant(N_obs,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 63;
      if (stan::math::logical_gt(D, 1)) {
        current_statement__ = 61;
        stan::model::assign(Corr,
          stan::math::multiply_lower_tri_self_transpose(L_Corr),
          "assigning variable Corr");
      } else {
        current_statement__ = 59;
        stan::model::assign(Corr, 1.0, "assigning variable Corr",
          stan::model::index_uni(1), stan::model::index_uni(1));
      }
      current_statement__ = 70;
      for (int n = 1; n <= N_obs; ++n) {
        current_statement__ = 68;
        if (stan::math::logical_lte(model_type, 2)) {
          current_statement__ = 66;
          stan::model::assign(log_lik,
            stan::math::bernoulli_logit_lpmf<false>(
              stan::model::rvalue(y, "y", stan::model::index_uni(n)),
              stan::model::rvalue(eta, "eta", stan::model::index_uni(n))),
            "assigning variable log_lik", stan::model::index_uni(n));
        } else {
          current_statement__ = 64;
          stan::model::assign(log_lik,
            stan::math::bernoulli_lpmf<false>(
              stan::model::rvalue(y, "y", stan::model::index_uni(n)),
              stan::model::rvalue(p, "p", stan::model::index_uni(n))),
            "assigning variable log_lik", stan::model::index_uni(n));
        }
      }
      out__.write(Corr);
      out__.write(log_lik);
    } 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> a_free =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(a_free_size,
          DUMMY_VAR__);
      current_statement__ = 1;
      stan::model::assign(a_free,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(a_free_size),
        "assigning variable a_free");
      out__.write_free_lb(0, a_free);
      Eigen::Matrix<local_scalar_t__,-1,1> b =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(I, DUMMY_VAR__);
      current_statement__ = 2;
      stan::model::assign(b,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(I),
        "assigning variable b");
      out__.write_free_lub(-4, 4, b);
      Eigen::Matrix<local_scalar_t__,-1,1> c =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(c_size, DUMMY_VAR__);
      current_statement__ = 3;
      stan::model::assign(c,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(c_size),
        "assigning variable c");
      out__.write_free_lub(c_mu, c_sigma, c);
      Eigen::Matrix<local_scalar_t__,-1,1> d =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(d_size, DUMMY_VAR__);
      current_statement__ = 4;
      stan::model::assign(d,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(d_size),
        "assigning variable d");
      out__.write_free_lub(d_mu, d_sigma, d);
      Eigen::Matrix<local_scalar_t__,-1,-1> L_Corr =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(L_Corr_1dim__,
          L_Corr_2dim__, DUMMY_VAR__);
      current_statement__ = 5;
      stan::model::assign(L_Corr,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,-1>>(L_Corr_1dim__,
          L_Corr_2dim__), "assigning variable L_Corr");
      out__.write_free_cholesky_factor_corr(L_Corr);
      std::vector<Eigen::Matrix<local_scalar_t__,-1,1>> theta_raw =
        std::vector<Eigen::Matrix<local_scalar_t__,-1,1>>(N,
          Eigen::Matrix<local_scalar_t__,-1,1>::Constant(D, DUMMY_VAR__));
      current_statement__ = 6;
      for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
        current_statement__ = 6;
        for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
          current_statement__ = 6;
          stan::model::assign(theta_raw, in__.read<local_scalar_t__>(),
            "assigning variable theta_raw", stan::model::index_uni(sym2__),
            stan::model::index_uni(sym1__));
        }
      }
      out__.write(theta_raw);
    } 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", "a_free", "double",
        std::vector<size_t>{static_cast<size_t>(a_free_size)});
      current_statement__ = 2;
      context__.validate_dims("parameter initialization", "b", "double",
        std::vector<size_t>{static_cast<size_t>(I)});
      current_statement__ = 3;
      context__.validate_dims("parameter initialization", "c", "double",
        std::vector<size_t>{static_cast<size_t>(c_size)});
      current_statement__ = 4;
      context__.validate_dims("parameter initialization", "d", "double",
        std::vector<size_t>{static_cast<size_t>(d_size)});
      current_statement__ = 5;
      context__.validate_dims("parameter initialization", "L_Corr", "double",
        std::vector<size_t>{static_cast<size_t>(L_Corr_1dim__),
          static_cast<size_t>(L_Corr_2dim__)});
      current_statement__ = 6;
      context__.validate_dims("parameter initialization", "theta_raw",
        "double",
        std::vector<size_t>{static_cast<size_t>(N), static_cast<size_t>(D)});
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      Eigen::Matrix<local_scalar_t__,-1,1> a_free =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(a_free_size,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> a_free_flat__;
        current_statement__ = 1;
        a_free_flat__ = context__.vals_r("a_free");
        current_statement__ = 1;
        pos__ = 1;
        current_statement__ = 1;
        for (int sym1__ = 1; sym1__ <= a_free_size; ++sym1__) {
          current_statement__ = 1;
          stan::model::assign(a_free, a_free_flat__[(pos__ - 1)],
            "assigning variable a_free", stan::model::index_uni(sym1__));
          current_statement__ = 1;
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_lb(0, a_free);
      Eigen::Matrix<local_scalar_t__,-1,1> b =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(I, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> b_flat__;
        current_statement__ = 2;
        b_flat__ = context__.vals_r("b");
        current_statement__ = 2;
        pos__ = 1;
        current_statement__ = 2;
        for (int sym1__ = 1; sym1__ <= I; ++sym1__) {
          current_statement__ = 2;
          stan::model::assign(b, b_flat__[(pos__ - 1)],
            "assigning variable b", stan::model::index_uni(sym1__));
          current_statement__ = 2;
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_lub(-4, 4, b);
      Eigen::Matrix<local_scalar_t__,-1,1> c =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(c_size, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> c_flat__;
        current_statement__ = 3;
        c_flat__ = context__.vals_r("c");
        current_statement__ = 3;
        pos__ = 1;
        current_statement__ = 3;
        for (int sym1__ = 1; sym1__ <= c_size; ++sym1__) {
          current_statement__ = 3;
          stan::model::assign(c, c_flat__[(pos__ - 1)],
            "assigning variable c", stan::model::index_uni(sym1__));
          current_statement__ = 3;
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_lub(c_mu, c_sigma, c);
      Eigen::Matrix<local_scalar_t__,-1,1> d =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(d_size, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> d_flat__;
        current_statement__ = 4;
        d_flat__ = context__.vals_r("d");
        current_statement__ = 4;
        pos__ = 1;
        current_statement__ = 4;
        for (int sym1__ = 1; sym1__ <= d_size; ++sym1__) {
          current_statement__ = 4;
          stan::model::assign(d, d_flat__[(pos__ - 1)],
            "assigning variable d", stan::model::index_uni(sym1__));
          current_statement__ = 4;
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_lub(d_mu, d_sigma, d);
      Eigen::Matrix<local_scalar_t__,-1,-1> L_Corr =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(L_Corr_1dim__,
          L_Corr_2dim__, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> L_Corr_flat__;
        current_statement__ = 5;
        L_Corr_flat__ = context__.vals_r("L_Corr");
        current_statement__ = 5;
        pos__ = 1;
        current_statement__ = 5;
        for (int sym1__ = 1; sym1__ <= L_Corr_2dim__; ++sym1__) {
          current_statement__ = 5;
          for (int sym2__ = 1; sym2__ <= L_Corr_1dim__; ++sym2__) {
            current_statement__ = 5;
            stan::model::assign(L_Corr, L_Corr_flat__[(pos__ - 1)],
              "assigning variable L_Corr", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 5;
            pos__ = (pos__ + 1);
          }
        }
      }
      out__.write_free_cholesky_factor_corr(L_Corr);
      std::vector<Eigen::Matrix<local_scalar_t__,-1,1>> theta_raw =
        std::vector<Eigen::Matrix<local_scalar_t__,-1,1>>(N,
          Eigen::Matrix<local_scalar_t__,-1,1>::Constant(D, DUMMY_VAR__));
      {
        std::vector<local_scalar_t__> theta_raw_flat__;
        current_statement__ = 6;
        theta_raw_flat__ = context__.vals_r("theta_raw");
        current_statement__ = 6;
        pos__ = 1;
        current_statement__ = 6;
        for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
          current_statement__ = 6;
          for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
            current_statement__ = 6;
            stan::model::assign(theta_raw, theta_raw_flat__[(pos__ - 1)],
              "assigning variable theta_raw", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 6;
            pos__ = (pos__ + 1);
          }
        }
      }
      out__.write(theta_raw);
    } 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>{"a_free", "b", "c", "d", "L_Corr",
                "theta_raw"};
    if (emit_transformed_parameters__) {
      std::vector<std::string> temp{"a", "theta", "eta", "p"};
      names__.reserve(names__.size() + temp.size());
      names__.insert(names__.end(), temp.begin(), temp.end());
    }
    if (emit_generated_quantities__) {
      std::vector<std::string> temp{"Corr", "log_lik"};
      names__.reserve(names__.size() + temp.size());
      names__.insert(names__.end(), temp.begin(), temp.end());
    }
  }
  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>(
                                                                    a_free_size)},
                std::vector<size_t>{static_cast<size_t>(I)},
                std::vector<size_t>{static_cast<size_t>(c_size)},
                std::vector<size_t>{static_cast<size_t>(d_size)},
                std::vector<size_t>{static_cast<size_t>(L_Corr_1dim__),
                  static_cast<size_t>(L_Corr_2dim__)},
                std::vector<size_t>{static_cast<size_t>(N),
                  static_cast<size_t>(D)}};
    if (emit_transformed_parameters__) {
      std::vector<std::vector<size_t>>
        temp{std::vector<size_t>{static_cast<size_t>(I),
               static_cast<size_t>(D)},
             std::vector<size_t>{static_cast<size_t>(N),
               static_cast<size_t>(D)},
             std::vector<size_t>{static_cast<size_t>(N_obs)},
             std::vector<size_t>{static_cast<size_t>(N_obs)}};
      dimss__.reserve(dimss__.size() + temp.size());
      dimss__.insert(dimss__.end(), temp.begin(), temp.end());
    }
    if (emit_generated_quantities__) {
      std::vector<std::vector<size_t>>
        temp{std::vector<size_t>{static_cast<size_t>(D),
               static_cast<size_t>(D)},
             std::vector<size_t>{static_cast<size_t>(N_obs)}};
      dimss__.reserve(dimss__.size() + temp.size());
      dimss__.insert(dimss__.end(), temp.begin(), temp.end());
    }
  }
  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__ <= a_free_size; ++sym1__) {
      param_names__.emplace_back(std::string() + "a_free" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= I; ++sym1__) {
      param_names__.emplace_back(std::string() + "b" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= c_size; ++sym1__) {
      param_names__.emplace_back(std::string() + "c" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= d_size; ++sym1__) {
      param_names__.emplace_back(std::string() + "d" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= L_Corr_2dim__; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= L_Corr_1dim__; ++sym2__) {
        param_names__.emplace_back(std::string() + "L_Corr" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
        param_names__.emplace_back(std::string() + "theta_raw" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    if (emit_transformed_parameters__) {
      for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= I; ++sym2__) {
          param_names__.emplace_back(std::string() + "a" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
          param_names__.emplace_back(std::string() + "theta" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= N_obs; ++sym1__) {
        param_names__.emplace_back(std::string() + "eta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= N_obs; ++sym1__) {
        param_names__.emplace_back(std::string() + "p" + '.' +
          std::to_string(sym1__));
      }
    }
    if (emit_generated_quantities__) {
      for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= D; ++sym2__) {
          param_names__.emplace_back(std::string() + "Corr" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= N_obs; ++sym1__) {
        param_names__.emplace_back(std::string() + "log_lik" + '.' +
          std::to_string(sym1__));
      }
    }
  }
  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__ <= a_free_size; ++sym1__) {
      param_names__.emplace_back(std::string() + "a_free" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= I; ++sym1__) {
      param_names__.emplace_back(std::string() + "b" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= c_size; ++sym1__) {
      param_names__.emplace_back(std::string() + "c" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= d_size; ++sym1__) {
      param_names__.emplace_back(std::string() + "d" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= ((L_Corr_1dim__ * (L_Corr_1dim__ - 1)) /
         2); ++sym1__) {
      param_names__.emplace_back(std::string() + "L_Corr" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
        param_names__.emplace_back(std::string() + "theta_raw" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    if (emit_transformed_parameters__) {
      for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= I; ++sym2__) {
          param_names__.emplace_back(std::string() + "a" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
          param_names__.emplace_back(std::string() + "theta" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= N_obs; ++sym1__) {
        param_names__.emplace_back(std::string() + "eta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= N_obs; ++sym1__) {
        param_names__.emplace_back(std::string() + "p" + '.' +
          std::to_string(sym1__));
      }
    }
    if (emit_generated_quantities__) {
      for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= D; ++sym2__) {
          param_names__.emplace_back(std::string() + "Corr" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= N_obs; ++sym1__) {
        param_names__.emplace_back(std::string() + "log_lik" + '.' +
          std::to_string(sym1__));
      }
    }
  }
  inline std::string get_constrained_sizedtypes() const {
    return std::string("[{\"name\":\"a_free\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(a_free_size) + "},\"block\":\"parameters\"},{\"name\":\"b\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(I) + "},\"block\":\"parameters\"},{\"name\":\"c\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(c_size) + "},\"block\":\"parameters\"},{\"name\":\"d\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(d_size) + "},\"block\":\"parameters\"},{\"name\":\"L_Corr\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(L_Corr_1dim__) + ",\"cols\":" + std::to_string(L_Corr_2dim__) + "},\"block\":\"parameters\"},{\"name\":\"theta_raw\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(N) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string(D) + "}},\"block\":\"parameters\"},{\"name\":\"a\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(I) + ",\"cols\":" + std::to_string(D) + "},\"block\":\"transformed_parameters\"},{\"name\":\"theta\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(N) + ",\"cols\":" + std::to_string(D) + "},\"block\":\"transformed_parameters\"},{\"name\":\"eta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_obs) + "},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_obs) + "},\"block\":\"transformed_parameters\"},{\"name\":\"Corr\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(D) + ",\"cols\":" + std::to_string(D) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_obs) + "},\"block\":\"generated_quantities\"}]");
  }
  inline std::string get_unconstrained_sizedtypes() const {
    return std::string("[{\"name\":\"a_free\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(a_free_size) + "},\"block\":\"parameters\"},{\"name\":\"b\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(I) + "},\"block\":\"parameters\"},{\"name\":\"c\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(c_size) + "},\"block\":\"parameters\"},{\"name\":\"d\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(d_size) + "},\"block\":\"parameters\"},{\"name\":\"L_Corr\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(((L_Corr_1dim__ * (L_Corr_1dim__ - 1)) /2)) + "},\"block\":\"parameters\"},{\"name\":\"theta_raw\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(N) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string(D) + "}},\"block\":\"parameters\"},{\"name\":\"a\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(I) + ",\"cols\":" + std::to_string(D) + "},\"block\":\"transformed_parameters\"},{\"name\":\"theta\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(N) + ",\"cols\":" + std::to_string(D) + "},\"block\":\"transformed_parameters\"},{\"name\":\"eta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_obs) + "},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_obs) + "},\"block\":\"transformed_parameters\"},{\"name\":\"Corr\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(D) + ",\"cols\":" + std::to_string(D) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_obs) + "},\"block\":\"generated_quantities\"}]");
  }
  // 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__ = (((((a_free_size + I) + c_size) + d_size) +
      (L_Corr_1dim__ * L_Corr_2dim__)) + (N * D));
    const size_t num_transformed = emit_transformed_parameters * (((((I * D)
      + (N * D)) + N_obs) + N_obs));
    const size_t num_gen_quantities = emit_generated_quantities * (((D * D) +
      N_obs));
    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__ = (((((a_free_size + I) + c_size) + d_size) +
      (L_Corr_1dim__ * L_Corr_2dim__)) + (N * D));
    const size_t num_transformed = emit_transformed_parameters * (((((I * D)
      + (N * D)) + N_obs) + N_obs));
    const size_t num_gen_quantities = emit_generated_quantities * (((D * D) +
      N_obs));
    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_MIRT_namespace::model_MIRT;
#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_MIRT_namespace::profiles__;
}
#endif
#endif
