// 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_FCMIRT_namespace {
using stan::model::model_base_crtp;
using namespace stan::math;
stan::math::profile_map profiles__;
static constexpr std::array<const char*, 257> locations_array__ =
  {" (found before start of program)",
  " (in 'string', line 149, column 2 to column 38)",
  " (in 'string', line 150, column 2 to column 29)",
  " (in 'string', line 151, column 2 to column 46)",
  " (in 'string', line 152, column 2 to column 46)",
  " (in 'string', line 153, column 2 to column 45)",
  " (in 'string', line 154, column 2 to column 31)",
  " (in 'string', line 157, column 2 to column 26)",
  " (in 'string', line 158, column 2 to column 14)",
  " (in 'string', line 159, column 2 to column 19)",
  " (in 'string', line 160, column 2 to column 19)",
  " (in 'string', line 161, column 2 to column 21)",
  " (in 'string', line 242, column 2 to column 20)",
  " (in 'string', line 243, column 2 to column 24)",
  " (in 'string', line 169, column 4 to column 16)",
  " (in 'string', line 176, column 10 to column 24)",
  " (in 'string', line 175, column 15 to line 177, column 9)",
  " (in 'string', line 173, column 10 to column 32)",
  " (in 'string', line 174, column 10 to column 19)",
  " (in 'string', line 172, column 33 to line 175, column 9)",
  " (in 'string', line 172, column 8 to line 177, column 9)",
  " (in 'string', line 171, column 21 to line 178, column 7)",
  " (in 'string', line 171, column 6 to line 178, column 7)",
  " (in 'string', line 170, column 19 to line 179, column 5)",
  " (in 'string', line 170, column 4 to line 179, column 5)",
  " (in 'string', line 168, column 9 to line 180, column 3)",
  " (in 'string', line 165, column 8 to column 33)",
  " (in 'string', line 164, column 21 to line 166, column 7)",
  " (in 'string', line 164, column 6 to line 166, column 7)",
  " (in 'string', line 163, column 19 to line 167, column 5)",
  " (in 'string', line 163, column 4 to line 167, column 5)",
  " (in 'string', line 162, column 23 to line 168, column 3)",
  " (in 'string', line 162, column 2 to line 180, column 3)",
  " (in 'string', line 182, column 4 to column 16)",
  " (in 'string', line 184, column 6 to column 27)",
  " (in 'string', line 185, column 6 to column 23)",
  " (in 'string', line 187, column 8 to column 54)",
  " (in 'string', line 188, column 8 to column 28)",
  " (in 'string', line 189, column 8 to column 29)",
  " (in 'string', line 190, column 8 to column 17)",
  " (in 'string', line 186, column 27 to line 191, column 7)",
  " (in 'string', line 186, column 6 to line 191, column 7)",
  " (in 'string', line 192, column 6 to column 55)",
  " (in 'string', line 183, column 21 to line 193, column 5)",
  " (in 'string', line 183, column 4 to line 193, column 5)",
  " (in 'string', line 181, column 2 to line 194, column 3)",
  " (in 'string', line 198, column 4 to column 32)",
  " (in 'string', line 197, column 9 to line 199, column 3)",
  " (in 'string', line 196, column 4 to column 15)",
  " (in 'string', line 195, column 23 to line 197, column 3)",
  " (in 'string', line 195, column 2 to line 199, column 3)",
  " (in 'string', line 203, column 4 to column 32)",
  " (in 'string', line 202, column 9 to line 204, column 3)",
  " (in 'string', line 201, column 4 to column 15)",
  " (in 'string', line 200, column 23 to line 202, column 3)",
  " (in 'string', line 200, column 2 to line 204, column 3)",
  " (in 'string', line 209, column 6 to column 50)",
  " (in 'string', line 208, column 11 to line 210, column 5)",
  " (in 'string', line 207, column 6 to column 53)",
  " (in 'string', line 206, column 15 to line 208, column 5)",
  " (in 'string', line 206, column 4 to line 210, column 5)",
  " (in 'string', line 205, column 17 to line 211, column 3)",
  " (in 'string', line 205, column 2 to line 211, column 3)",
  " (in 'string', line 247, column 4 to column 21)",
  " (in 'string', line 246, column 9 to line 248, column 3)",
  " (in 'string', line 245, column 4 to column 53)",
  " (in 'string', line 244, column 13 to line 246, column 3)",
  " (in 'string', line 244, column 2 to line 248, column 3)",
  " (in 'string', line 250, column 4 to line 257, column 6)",
  " (in 'string', line 249, column 23 to line 258, column 3)",
  " (in 'string', line 249, column 2 to line 258, column 3)",
  " (in 'string', line 215, column 4 to column 38)",
  " (in 'string', line 214, column 23 to line 216, column 3)",
  " (in 'string', line 214, column 2 to line 216, column 3)",
  " (in 'string', line 217, column 2 to column 28)",
  " (in 'string', line 219, column 4 to column 31)",
  " (in 'string', line 218, column 23 to line 220, column 3)",
  " (in 'string', line 218, column 2 to line 220, column 3)",
  " (in 'string', line 222, column 4 to column 31)",
  " (in 'string', line 221, column 23 to line 223, column 3)",
  " (in 'string', line 221, column 2 to line 223, column 3)",
  " (in 'string', line 225, column 4 to column 34)",
  " (in 'string', line 224, column 13 to line 226, column 3)",
  " (in 'string', line 224, column 2 to line 226, column 3)",
  " (in 'string', line 228, column 4 to column 32)",
  " (in 'string', line 227, column 17 to line 229, column 3)",
  " (in 'string', line 227, column 2 to line 229, column 3)",
  " (in 'string', line 231, column 4 to line 238, column 6)",
  " (in 'string', line 230, column 23 to line 239, column 3)",
  " (in 'string', line 230, column 2 to line 239, column 3)",
  " (in 'string', line 93, column 2 to column 21)",
  " (in 'string', line 94, column 2 to column 17)",
  " (in 'string', line 95, column 2 to column 17)",
  " (in 'string', line 96, column 2 to column 17)",
  " (in 'string', line 97, column 2 to column 17)",
  " (in 'string', line 98, column 2 to column 35)",
  " (in 'string', line 99, column 8 to column 13)",
  " (in 'string', line 99, column 2 to column 41)",
  " (in 'string', line 100, column 8 to column 13)",
  " (in 'string', line 100, column 2 to column 41)",
  " (in 'string', line 101, column 8 to column 13)",
  " (in 'string', line 101, column 2 to column 30)",
  " (in 'string', line 102, column 9 to column 10)",
  " (in 'string', line 102, column 12 to column 13)",
  " (in 'string', line 102, column 2 to column 24)",
  " (in 'string', line 103, column 8 to column 9)",
  " (in 'string', line 103, column 2 to column 32)",
  " (in 'string', line 104, column 8 to column 9)",
  " (in 'string', line 104, column 2 to column 41)",
  " (in 'string', line 105, column 2 to column 33)",
  " (in 'string', line 106, column 8 to column 25)",
  " (in 'string', line 106, column 2 to column 61)",
  " (in 'string', line 107, column 8 to column 13)",
  " (in 'string', line 107, column 2 to column 39)",
  " (in 'string', line 108, column 8 to column 9)",
  " (in 'string', line 108, column 2 to column 32)",
  " (in 'string', line 109, column 2 to column 33)",
  " (in 'string', line 110, column 8 to column 25)",
  " (in 'string', line 110, column 2 to column 55)",
  " (in 'string', line 111, column 8 to column 13)",
  " (in 'string', line 111, column 2 to column 40)",
  " (in 'string', line 112, column 8 to column 9)",
  " (in 'string', line 112, column 2 to column 30)",
  " (in 'string', line 113, column 2 to column 31)",
  " (in 'string', line 114, column 8 to column 23)",
  " (in 'string', line 114, column 2 to column 51)",
  " (in 'string', line 115, column 8 to column 13)",
  " (in 'string', line 115, column 2 to column 38)",
  " (in 'string', line 116, column 8 to column 9)",
  " (in 'string', line 116, column 2 to column 31)",
  " (in 'string', line 117, column 2 to column 12)",
  " (in 'string', line 118, column 2 to column 24)",
  " (in 'string', line 119, column 2 to column 12)",
  " (in 'string', line 120, column 2 to column 24)",
  " (in 'string', line 121, column 2 to column 12)",
  " (in 'string', line 122, column 2 to column 24)",
  " (in 'string', line 123, column 2 to column 12)",
  " (in 'string', line 124, column 2 to column 24)",
  " (in 'string', line 125, column 9 to column 10)",
  " (in 'string', line 125, column 2 to column 21)",
  " (in 'string', line 128, column 2 to column 22)",
  " (in 'string', line 129, column 2 to column 26)",
  " (in 'string', line 130, column 2 to column 17)",
  " (in 'string', line 131, column 2 to column 17)",
  " (in 'string', line 136, column 10 to column 27)",
  " (in 'string', line 135, column 33 to line 137, column 9)",
  " (in 'string', line 135, column 8 to line 137, column 9)",
  " (in 'string', line 134, column 21 to line 138, column 7)",
  " (in 'string', line 134, column 6 to line 138, column 7)",
  " (in 'string', line 133, column 19 to line 139, column 5)",
  " (in 'string', line 133, column 4 to line 139, column 5)",
  " (in 'string', line 132, column 23 to line 140, column 3)",
  " (in 'string', line 132, column 2 to line 140, column 3)",
  " (in 'string', line 142, column 4 to column 15)",
  " (in 'string', line 141, column 23 to line 143, column 3)",
  " (in 'string', line 141, column 2 to line 143, column 3)",
  " (in 'string', line 145, column 4 to column 15)",
  " (in 'string', line 144, column 23 to line 146, column 3)",
  " (in 'string', line 144, column 2 to line 146, column 3)",
  " (in 'string', line 149, column 18 to column 29)",
  " (in 'string', line 150, column 9 to column 20)",
  " (in 'string', line 151, column 36 to column 42)",
  " (in 'string', line 152, column 36 to column 42)",
  " (in 'string', line 153, column 23 to column 36)",
  " (in 'string', line 154, column 8 to column 9)",
  " (in 'string', line 154, column 18 to column 19)",
  " (in 'string', line 157, column 18 to column 19)",
  " (in 'string', line 157, column 21 to column 22)",
  " (in 'string', line 158, column 9 to column 10)",
  " (in 'string', line 159, column 9 to column 10)",
  " (in 'string', line 160, column 9 to column 10)",
  " (in 'string', line 161, column 9 to column 10)",
  " (in 'string', line 161, column 12 to column 13)",
  " (in 'string', line 242, column 9 to column 10)",
  " (in 'string', line 242, column 12 to column 13)",
  " (in 'string', line 243, column 9 to column 14)",
  " (in 'string', line 13, column 4 to column 25)",
  " (in 'string', line 14, column 11 to column 12)",
  " (in 'string', line 14, column 4 to column 24)",
  " (in 'string', line 15, column 11 to column 12)",
  " (in 'string', line 15, column 4 to column 27)",
  " (in 'string', line 17, column 6 to column 52)",
  " (in 'string', line 18, column 6 to column 58)",
  " (in 'string', line 19, column 6 to column 19)",
  " (in 'string', line 25, column 8 to column 33)",
  " (in 'string', line 24, column 13 to line 26, column 7)",
  " (in 'string', line 23, column 8 to column 71)",
  " (in 'string', line 22, column 34 to line 24, column 7)",
  " (in 'string', line 22, column 13 to line 26, column 7)",
  " (in 'string', line 21, column 8 to column 65)",
  " (in 'string', line 20, column 27 to line 22, column 7)",
  " (in 'string', line 20, column 6 to line 26, column 7)",
  " (in 'string', line 27, column 6 to column 56)",
  " (in 'string', line 28, column 6 to column 34)",
  " (in 'string', line 29, column 6 to column 39)",
  " (in 'string', line 16, column 19 to line 30, column 5)",
  " (in 'string', line 16, column 4 to line 30, column 5)",
  " (in 'string', line 32, column 6 to column 31)",
  " (in 'string', line 33, column 6 to column 37)",
  " (in 'string', line 34, column 13 to column 18)",
  " (in 'string', line 34, column 6 to column 29)",
  " (in 'string', line 36, column 8 to column 20)",
  " (in 'string', line 39, column 12 to column 38)",
  " (in 'string', line 40, column 19 to column 20)",
  " (in 'string', line 40, column 12 to column 30)",
  " (in 'string', line 41, column 12 to column 31)",
  " (in 'string', line 43, column 14 to column 38)",
  " (in 'string', line 44, column 14 to column 76)",
  " (in 'string', line 45, column 14 to column 47)",
  " (in 'string', line 48, column 18 to column 76)",
  " (in 'string', line 49, column 18 to column 46)",
  " (in 'string', line 47, column 28 to line 50, column 17)",
  " (in 'string', line 47, column 16 to line 50, column 17)",
  " (in 'string', line 46, column 31 to line 51, column 15)",
  " (in 'string', line 46, column 14 to line 51, column 15)",
  " (in 'string', line 52, column 14 to column 36)",
  " (in 'string', line 54, column 16 to column 33)",
  " (in 'string', line 53, column 30 to line 55, column 15)",
  " (in 'string', line 53, column 14 to line 55, column 15)",
  " (in 'string', line 42, column 37 to line 56, column 13)",
  " (in 'string', line 42, column 12 to line 56, column 13)",
  " (in 'string', line 57, column 12 to column 62)",
  " (in 'string', line 38, column 33 to line 58, column 11)",
  " (in 'string', line 38, column 10 to line 58, column 11)",
  " (in 'string', line 37, column 19 to line 59, column 9)",
  " (in 'string', line 37, column 8 to line 59, column 9)",
  " (in 'string', line 60, column 8 to column 25)",
  " (in 'string', line 35, column 25 to line 61, column 7)",
  " (in 'string', line 35, column 6 to line 61, column 7)",
  " (in 'string', line 63, column 8 to column 32)",
  " (in 'string', line 64, column 8 to column 37)",
  " (in 'string', line 65, column 8 to column 30)",
  " (in 'string', line 66, column 8 to column 42)",
  " (in 'string', line 68, column 10 to column 51)",
  " (in 'string', line 67, column 23 to line 69, column 9)",
  " (in 'string', line 67, column 8 to line 69, column 9)",
  " (in 'string', line 71, column 10 to column 29)",
  " (in 'string', line 79, column 12 to column 64)",
  " (in 'string', line 80, column 12 to column 68)",
  " (in 'string', line 81, column 12 to column 46)",
  " (in 'string', line 78, column 17 to line 82, column 11)",
  " (in 'string', line 73, column 12 to column 64)",
  " (in 'string', line 74, column 12 to column 72)",
  " (in 'string', line 75, column 12 to column 68)",
  " (in 'string', line 76, column 12 to column 72)",
  " (in 'string', line 77, column 12 to column 68)",
  " (in 'string', line 72, column 25 to line 78, column 11)",
  " (in 'string', line 72, column 10 to line 82, column 11)",
  " (in 'string', line 84, column 12 to column 54)",
  " (in 'string', line 83, column 26 to line 85, column 11)",
  " (in 'string', line 83, column 10 to line 85, column 11)",
  " (in 'string', line 70, column 27 to line 86, column 9)",
  " (in 'string', line 70, column 8 to line 86, column 9)",
  " (in 'string', line 87, column 8 to column 40)",
  " (in 'string', line 62, column 6 to line 88, column 7)",
  " (in 'string', line 31, column 4 to line 89, column 5)",
  " (in 'string', line 12, column 4 to line 90, column 3)"};
template <typename T4__, typename T5__, typename T6__, typename T7__,
          typename T8__,
          stan::require_all_t<stan::is_eigen_matrix_dynamic<T4__>,
                              stan::is_vt_not_complex<T4__>,
                              stan::is_eigen_matrix_dynamic<T5__>,
                              stan::is_vt_not_complex<T5__>,
                              stan::is_col_vector<T6__>,
                              stan::is_vt_not_complex<T6__>,
                              stan::is_col_vector<T7__>,
                              stan::is_vt_not_complex<T7__>,
                              stan::is_col_vector<T8__>,
                              stan::is_vt_not_complex<T8__>>* = nullptr>
stan::promote_args_t<stan::base_type_t<T4__>, stan::base_type_t<T5__>,
  stan::base_type_t<T6__>, stan::base_type_t<T7__>, stan::base_type_t<T8__>>
fcmirt_obs_ll(const int& p, const int& blk, const int& y_obs, const int&
              model_type, const T4__& theta_arg__, const T5__& a_arg__,
              const T6__& b_par_arg__, const T7__& c_par_arg__, const T8__&
              d_par_arg__, const std::vector<int>& n_items,
              const std::vector<int>& fc_type, const std::vector<int>&
              block_items, const std::vector<int>& item_start,
              const std::vector<int>& n_total, const std::vector<int>&
              patterns_total, const std::vector<int>& total_start,
              const std::vector<int>& patterns_obs, const std::vector<int>&
              obs_start, const std::vector<int>& fc_len, std::ostream*
              pstream__);
template <typename T4__, typename T5__, typename T6__, typename T7__,
          typename T8__,
          stan::require_all_t<stan::is_eigen_matrix_dynamic<T4__>,
                              stan::is_vt_not_complex<T4__>,
                              stan::is_eigen_matrix_dynamic<T5__>,
                              stan::is_vt_not_complex<T5__>,
                              stan::is_col_vector<T6__>,
                              stan::is_vt_not_complex<T6__>,
                              stan::is_col_vector<T7__>,
                              stan::is_vt_not_complex<T7__>,
                              stan::is_col_vector<T8__>,
                              stan::is_vt_not_complex<T8__>>*>
stan::promote_args_t<stan::base_type_t<T4__>, stan::base_type_t<T5__>,
  stan::base_type_t<T6__>, stan::base_type_t<T7__>, stan::base_type_t<T8__>>
fcmirt_obs_ll(const int& p, const int& blk, const int& y_obs, const int&
              model_type, const T4__& theta_arg__, const T5__& a_arg__,
              const T6__& b_par_arg__, const T7__& c_par_arg__, const T8__&
              d_par_arg__, const std::vector<int>& n_items,
              const std::vector<int>& fc_type, const std::vector<int>&
              block_items, const std::vector<int>& item_start,
              const std::vector<int>& n_total, const std::vector<int>&
              patterns_total, const std::vector<int>& total_start,
              const std::vector<int>& patterns_obs, const std::vector<int>&
              obs_start, const std::vector<int>& fc_len, std::ostream*
              pstream__) {
  using local_scalar_t__ = stan::promote_args_t<stan::base_type_t<T4__>,
                             stan::base_type_t<T5__>,
                             stan::base_type_t<T6__>,
                             stan::base_type_t<T7__>,
                             stan::base_type_t<T8__>>;
  int current_statement__ = 0;
  const auto& theta = stan::math::to_ref(theta_arg__);
  const auto& a = stan::math::to_ref(a_arg__);
  const auto& b_par = stan::math::to_ref(b_par_arg__);
  const auto& c_par = stan::math::to_ref(c_par_arg__);
  const auto& d_par = stan::math::to_ref(d_par_arg__);
  static constexpr bool propto__ = true;
  // suppress unused var warning
  (void) propto__;
  local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  // suppress unused var warning
  (void) DUMMY_VAR__;
  try {
    int K = std::numeric_limits<int>::min();
    current_statement__ = 176;
    K = stan::model::rvalue(n_items, "n_items", stan::model::index_uni(blk));
    current_statement__ = 177;
    stan::math::validate_non_negative_index("log_agree", "K", K);
    Eigen::Matrix<local_scalar_t__,-1,1> log_agree =
      Eigen::Matrix<local_scalar_t__,-1,1>::Constant(K, DUMMY_VAR__);
    current_statement__ = 179;
    stan::math::validate_non_negative_index("log_disagree", "K", K);
    Eigen::Matrix<local_scalar_t__,-1,1> log_disagree =
      Eigen::Matrix<local_scalar_t__,-1,1>::Constant(K, DUMMY_VAR__);
    current_statement__ = 196;
    for (int k = 1; k <= K; ++k) {
      int gi = std::numeric_limits<int>::min();
      current_statement__ = 181;
      gi = stan::model::rvalue(block_items, "block_items",
             stan::model::index_uni(
               ((stan::model::rvalue(item_start, "item_start",
                   stan::model::index_uni(blk)) + k) - 1)));
      local_scalar_t__ eta = DUMMY_VAR__;
      current_statement__ = 182;
      eta = (stan::math::dot_product(
               stan::model::rvalue(theta, "theta", stan::model::index_uni(p)),
               stan::model::rvalue(a, "a", stan::model::index_uni(gi)))
        - stan::model::rvalue(b_par, "b_par", stan::model::index_uni(gi)));
      local_scalar_t__ p_agree = DUMMY_VAR__;
      current_statement__ = 191;
      if (stan::math::logical_eq(model_type, 3)) {
        current_statement__ = 189;
        p_agree = (stan::model::rvalue(c_par, "c_par",
                     stan::model::index_uni(gi))
          + ((1.0 -
          stan::model::rvalue(c_par, "c_par", stan::model::index_uni(gi))) *
          stan::math::inv_logit(eta)));
      } else {
        current_statement__ = 188;
        if (stan::math::logical_eq(model_type, 4)) {
          current_statement__ = 186;
          p_agree = (stan::model::rvalue(c_par, "c_par",
                       stan::model::index_uni(gi))
            +
            ((stan::model::rvalue(d_par, "d_par", stan::model::index_uni(gi))
            -
            stan::model::rvalue(c_par, "c_par", stan::model::index_uni(gi)))
            * stan::math::inv_logit(eta)));
        } else {
          current_statement__ = 184;
          p_agree = stan::math::inv_logit(eta);
        }
      }
      current_statement__ = 192;
      p_agree = stan::math::fmin((1.0 - 1e-12),
                  stan::math::fmax(1e-12, p_agree));
      current_statement__ = 193;
      stan::model::assign(log_agree, stan::math::log(p_agree),
        "assigning variable log_agree", stan::model::index_uni(k));
      current_statement__ = 194;
      stan::model::assign(log_disagree, stan::math::log1m(p_agree),
        "assigning variable log_disagree", stan::model::index_uni(k));
    }
    {
      int n_tot = std::numeric_limits<int>::min();
      current_statement__ = 197;
      n_tot = stan::model::rvalue(n_total, "n_total",
                stan::model::index_uni(blk));
      int t_start = std::numeric_limits<int>::min();
      current_statement__ = 198;
      t_start = stan::model::rvalue(total_start, "total_start",
                  stan::model::index_uni(blk));
      current_statement__ = 199;
      stan::math::validate_non_negative_index("lp_total", "n_tot", n_tot);
      Eigen::Matrix<local_scalar_t__,-1,1> lp_total =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_tot, DUMMY_VAR__);
      current_statement__ = 228;
      for (int t = 1; t <= n_tot; ++t) {
        local_scalar_t__ lp = DUMMY_VAR__;
        current_statement__ = 201;
        lp = 0;
        current_statement__ = 225;
        if (stan::math::logical_gt(K, 1)) {
          current_statement__ = 223;
          for (int pos = 1; pos <= (K - 1); ++pos) {
            int rem_len = std::numeric_limits<int>::min();
            current_statement__ = 202;
            rem_len = ((K - pos) + 1);
            current_statement__ = 203;
            stan::math::validate_non_negative_index("pick_lp", "K", K);
            Eigen::Matrix<local_scalar_t__,-1,1> pick_lp =
              Eigen::Matrix<local_scalar_t__,-1,1>::Constant(K, DUMMY_VAR__);
            local_scalar_t__ chosen_lp = DUMMY_VAR__;
            current_statement__ = 205;
            chosen_lp = 0;
            current_statement__ = 220;
            for (int h_pos = 1; h_pos <= rem_len; ++h_pos) {
              int h = std::numeric_limits<int>::min();
              current_statement__ = 206;
              h = ((pos + h_pos) - 1);
              int candidate = std::numeric_limits<int>::min();
              current_statement__ = 207;
              candidate = stan::model::rvalue(patterns_total,
                            "patterns_total",
                            stan::model::index_uni((((t_start + ((t - 1) *
                              K)) + h) - 1)));
              local_scalar_t__ term = DUMMY_VAR__;
              current_statement__ = 208;
              term = stan::model::rvalue(log_agree, "log_agree",
                       stan::model::index_uni(candidate));
              current_statement__ = 214;
              for (int g = pos; g <= K; ++g) {
                current_statement__ = 212;
                if (stan::math::logical_neq(g, h)) {
                  int other = std::numeric_limits<int>::min();
                  current_statement__ = 209;
                  other = stan::model::rvalue(patterns_total,
                            "patterns_total",
                            stan::model::index_uni((((t_start + ((t - 1) *
                              K)) + g) - 1)));
                  current_statement__ = 210;
                  term = (term +
                    stan::model::rvalue(log_disagree, "log_disagree",
                      stan::model::index_uni(other)));
                }
              }
              current_statement__ = 215;
              stan::model::assign(pick_lp, term,
                "assigning variable pick_lp", stan::model::index_uni(h_pos));
              current_statement__ = 218;
              if (stan::math::logical_eq(h_pos, 1)) {
                current_statement__ = 216;
                chosen_lp = term;
              }
            }
            current_statement__ = 221;
            lp = (lp + (chosen_lp -
              stan::math::log_sum_exp(
                stan::model::rvalue(pick_lp, "pick_lp",
                  stan::model::index_min_max(1, rem_len)))));
          }
        }
        current_statement__ = 226;
        stan::model::assign(lp_total, lp, "assigning variable lp_total",
          stan::model::index_uni(t));
      }
      {
        int fc_t = std::numeric_limits<int>::min();
        current_statement__ = 229;
        fc_t = stan::model::rvalue(fc_type, "fc_type",
                 stan::model::index_uni(blk));
        int o_start = std::numeric_limits<int>::min();
        current_statement__ = 230;
        o_start = stan::model::rvalue(obs_start, "obs_start",
                    stan::model::index_uni(blk));
        int fcl = std::numeric_limits<int>::min();
        current_statement__ = 231;
        fcl = stan::model::rvalue(fc_len, "fc_len",
                stan::model::index_uni(blk));
        local_scalar_t__ lp_obs = DUMMY_VAR__;
        current_statement__ = 232;
        lp_obs = stan::math::negative_infinity();
        current_statement__ = 235;
        if (stan::math::logical_eq(fc_t, 1)) {
          current_statement__ = 233;
          return stan::math::fmax(
                   stan::model::rvalue(lp_total, "lp_total",
                     stan::model::index_uni(y_obs)), stan::math::log(1e-16));
        }
        current_statement__ = 252;
        for (int t = 1; t <= n_tot; ++t) {
          int consistent = std::numeric_limits<int>::min();
          current_statement__ = 236;
          consistent = 0;
          current_statement__ = 247;
          if (stan::math::logical_eq(fc_t, 2)) {
            int first_t = std::numeric_limits<int>::min();
            current_statement__ = 241;
            first_t = stan::model::rvalue(patterns_total, "patterns_total",
                        stan::model::index_uni((t_start + ((t - 1) * K))));
            int last_t = std::numeric_limits<int>::min();
            current_statement__ = 242;
            last_t = stan::model::rvalue(patterns_total, "patterns_total",
                       stan::model::index_uni((((t_start + ((t - 1) * K)) +
                         K) - 1)));
            int first_o = std::numeric_limits<int>::min();
            current_statement__ = 243;
            first_o = stan::model::rvalue(patterns_obs, "patterns_obs",
                        stan::model::index_uni((o_start + ((y_obs - 1) *
                          fcl))));
            int last_o = std::numeric_limits<int>::min();
            current_statement__ = 244;
            last_o = stan::model::rvalue(patterns_obs, "patterns_obs",
                       stan::model::index_uni(((o_start + ((y_obs - 1) *
                         fcl)) + 1)));
            current_statement__ = 245;
            consistent = (stan::math::primitive_value(
                            stan::math::logical_eq(first_t, first_o))
              &&
              stan::math::primitive_value(
                stan::math::logical_eq(last_t, last_o)));
          } else {
            int first_t = std::numeric_limits<int>::min();
            current_statement__ = 237;
            first_t = stan::model::rvalue(patterns_total, "patterns_total",
                        stan::model::index_uni((t_start + ((t - 1) * K))));
            int first_o = std::numeric_limits<int>::min();
            current_statement__ = 238;
            first_o = stan::model::rvalue(patterns_obs, "patterns_obs",
                        stan::model::index_uni((o_start + ((y_obs - 1) *
                          fcl))));
            current_statement__ = 239;
            consistent = stan::math::logical_eq(first_t, first_o);
          }
          current_statement__ = 250;
          if (consistent) {
            current_statement__ = 248;
            lp_obs = stan::math::log_sum_exp(lp_obs,
                       stan::model::rvalue(lp_total, "lp_total",
                         stan::model::index_uni(t)));
          }
        }
        current_statement__ = 253;
        return stan::math::fmax(lp_obs, stan::math::log(1e-16));
      }
    }
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
#include <stan_meta_header.hpp>
class model_FCMIRT final : public model_base_crtp<model_FCMIRT> {
private:
  int N_obs;
  int N;
  int B;
  int I;
  int D;
  int model_type;
  std::vector<int> pid;
  std::vector<int> bid;
  std::vector<int> y;
  Eigen::Matrix<double,-1,-1> Q_matrix_data__;
  std::vector<int> n_items;
  std::vector<int> fc_type;
  int total_block_items;
  std::vector<int> block_items;
  std::vector<int> item_start;
  std::vector<int> n_total;
  int total_cells_total;
  std::vector<int> patterns_total;
  std::vector<int> total_start;
  std::vector<int> n_obs;
  int total_cells_obs;
  std::vector<int> patterns_obs;
  std::vector<int> obs_start;
  std::vector<int> fc_len;
  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 b_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_FCMIRT() {}
  model_FCMIRT(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_FCMIRT_namespace::model_FCMIRT";
    // 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__ = 90;
      context__.validate_dims("data initialization", "N_obs", "int",
        std::vector<size_t>{});
      N_obs = std::numeric_limits<int>::min();
      current_statement__ = 90;
      N_obs = context__.vals_i("N_obs")[(1 - 1)];
      current_statement__ = 90;
      stan::math::check_greater_or_equal(function__, "N_obs", N_obs, 1);
      current_statement__ = 91;
      context__.validate_dims("data initialization", "N", "int",
        std::vector<size_t>{});
      N = std::numeric_limits<int>::min();
      current_statement__ = 91;
      N = context__.vals_i("N")[(1 - 1)];
      current_statement__ = 91;
      stan::math::check_greater_or_equal(function__, "N", N, 1);
      current_statement__ = 92;
      context__.validate_dims("data initialization", "B", "int",
        std::vector<size_t>{});
      B = std::numeric_limits<int>::min();
      current_statement__ = 92;
      B = context__.vals_i("B")[(1 - 1)];
      current_statement__ = 92;
      stan::math::check_greater_or_equal(function__, "B", B, 1);
      current_statement__ = 93;
      context__.validate_dims("data initialization", "I", "int",
        std::vector<size_t>{});
      I = std::numeric_limits<int>::min();
      current_statement__ = 93;
      I = context__.vals_i("I")[(1 - 1)];
      current_statement__ = 93;
      stan::math::check_greater_or_equal(function__, "I", I, 1);
      current_statement__ = 94;
      context__.validate_dims("data initialization", "D", "int",
        std::vector<size_t>{});
      D = std::numeric_limits<int>::min();
      current_statement__ = 94;
      D = context__.vals_i("D")[(1 - 1)];
      current_statement__ = 94;
      stan::math::check_greater_or_equal(function__, "D", D, 1);
      current_statement__ = 95;
      context__.validate_dims("data initialization", "model_type", "int",
        std::vector<size_t>{});
      model_type = std::numeric_limits<int>::min();
      current_statement__ = 95;
      model_type = context__.vals_i("model_type")[(1 - 1)];
      current_statement__ = 95;
      stan::math::check_greater_or_equal(function__, "model_type",
        model_type, 1);
      current_statement__ = 95;
      stan::math::check_less_or_equal(function__, "model_type", model_type, 4);
      current_statement__ = 96;
      stan::math::validate_non_negative_index("pid", "N_obs", N_obs);
      current_statement__ = 97;
      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__ = 97;
      pid = context__.vals_i("pid");
      current_statement__ = 97;
      stan::math::check_greater_or_equal(function__, "pid", pid, 1);
      current_statement__ = 97;
      stan::math::check_less_or_equal(function__, "pid", pid, N);
      current_statement__ = 98;
      stan::math::validate_non_negative_index("bid", "N_obs", N_obs);
      current_statement__ = 99;
      context__.validate_dims("data initialization", "bid", "int",
        std::vector<size_t>{static_cast<size_t>(N_obs)});
      bid = std::vector<int>(N_obs, std::numeric_limits<int>::min());
      current_statement__ = 99;
      bid = context__.vals_i("bid");
      current_statement__ = 99;
      stan::math::check_greater_or_equal(function__, "bid", bid, 1);
      current_statement__ = 99;
      stan::math::check_less_or_equal(function__, "bid", bid, B);
      current_statement__ = 100;
      stan::math::validate_non_negative_index("y", "N_obs", N_obs);
      current_statement__ = 101;
      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__ = 101;
      y = context__.vals_i("y");
      current_statement__ = 101;
      stan::math::check_greater_or_equal(function__, "y", y, 1);
      current_statement__ = 102;
      stan::math::validate_non_negative_index("Q_matrix", "I", I);
      current_statement__ = 103;
      stan::math::validate_non_negative_index("Q_matrix", "D", D);
      current_statement__ = 104;
      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__ = 104;
        Q_matrix_flat__ = context__.vals_r("Q_matrix");
        current_statement__ = 104;
        pos__ = 1;
        current_statement__ = 104;
        for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
          current_statement__ = 104;
          for (int sym2__ = 1; sym2__ <= I; ++sym2__) {
            current_statement__ = 104;
            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__ = 104;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 105;
      stan::math::validate_non_negative_index("n_items", "B", B);
      current_statement__ = 106;
      context__.validate_dims("data initialization", "n_items", "int",
        std::vector<size_t>{static_cast<size_t>(B)});
      n_items = std::vector<int>(B, std::numeric_limits<int>::min());
      current_statement__ = 106;
      n_items = context__.vals_i("n_items");
      current_statement__ = 106;
      stan::math::check_greater_or_equal(function__, "n_items", n_items, 1);
      current_statement__ = 107;
      stan::math::validate_non_negative_index("fc_type", "B", B);
      current_statement__ = 108;
      context__.validate_dims("data initialization", "fc_type", "int",
        std::vector<size_t>{static_cast<size_t>(B)});
      fc_type = std::vector<int>(B, std::numeric_limits<int>::min());
      current_statement__ = 108;
      fc_type = context__.vals_i("fc_type");
      current_statement__ = 108;
      stan::math::check_greater_or_equal(function__, "fc_type", fc_type, 1);
      current_statement__ = 108;
      stan::math::check_less_or_equal(function__, "fc_type", fc_type, 3);
      current_statement__ = 109;
      context__.validate_dims("data initialization", "total_block_items",
        "int", std::vector<size_t>{});
      total_block_items = std::numeric_limits<int>::min();
      current_statement__ = 109;
      total_block_items = context__.vals_i("total_block_items")[(1 - 1)];
      current_statement__ = 109;
      stan::math::check_greater_or_equal(function__, "total_block_items",
        total_block_items, 1);
      current_statement__ = 110;
      stan::math::validate_non_negative_index("block_items",
        "total_block_items", total_block_items);
      current_statement__ = 111;
      context__.validate_dims("data initialization", "block_items", "int",
        std::vector<size_t>{static_cast<size_t>(total_block_items)});
      block_items = std::vector<int>(total_block_items,
                      std::numeric_limits<int>::min());
      current_statement__ = 111;
      block_items = context__.vals_i("block_items");
      current_statement__ = 111;
      stan::math::check_greater_or_equal(function__, "block_items",
        block_items, 1);
      current_statement__ = 111;
      stan::math::check_less_or_equal(function__, "block_items", block_items,
        I);
      current_statement__ = 112;
      stan::math::validate_non_negative_index("item_start", "B + 1", (B + 1));
      current_statement__ = 113;
      context__.validate_dims("data initialization", "item_start", "int",
        std::vector<size_t>{static_cast<size_t>((B + 1))});
      item_start = std::vector<int>((B + 1), std::numeric_limits<int>::min());
      current_statement__ = 113;
      item_start = context__.vals_i("item_start");
      current_statement__ = 113;
      stan::math::check_greater_or_equal(function__, "item_start",
        item_start, 1);
      current_statement__ = 114;
      stan::math::validate_non_negative_index("n_total", "B", B);
      current_statement__ = 115;
      context__.validate_dims("data initialization", "n_total", "int",
        std::vector<size_t>{static_cast<size_t>(B)});
      n_total = std::vector<int>(B, std::numeric_limits<int>::min());
      current_statement__ = 115;
      n_total = context__.vals_i("n_total");
      current_statement__ = 115;
      stan::math::check_greater_or_equal(function__, "n_total", n_total, 1);
      current_statement__ = 116;
      context__.validate_dims("data initialization", "total_cells_total",
        "int", std::vector<size_t>{});
      total_cells_total = std::numeric_limits<int>::min();
      current_statement__ = 116;
      total_cells_total = context__.vals_i("total_cells_total")[(1 - 1)];
      current_statement__ = 116;
      stan::math::check_greater_or_equal(function__, "total_cells_total",
        total_cells_total, 1);
      current_statement__ = 117;
      stan::math::validate_non_negative_index("patterns_total",
        "total_cells_total", total_cells_total);
      current_statement__ = 118;
      context__.validate_dims("data initialization", "patterns_total", "int",
        std::vector<size_t>{static_cast<size_t>(total_cells_total)});
      patterns_total = std::vector<int>(total_cells_total,
                         std::numeric_limits<int>::min());
      current_statement__ = 118;
      patterns_total = context__.vals_i("patterns_total");
      current_statement__ = 118;
      stan::math::check_greater_or_equal(function__, "patterns_total",
        patterns_total, 1);
      current_statement__ = 119;
      stan::math::validate_non_negative_index("total_start", "B + 1", (B + 1));
      current_statement__ = 120;
      context__.validate_dims("data initialization", "total_start", "int",
        std::vector<size_t>{static_cast<size_t>((B + 1))});
      total_start = std::vector<int>((B + 1),
                      std::numeric_limits<int>::min());
      current_statement__ = 120;
      total_start = context__.vals_i("total_start");
      current_statement__ = 120;
      stan::math::check_greater_or_equal(function__, "total_start",
        total_start, 1);
      current_statement__ = 121;
      stan::math::validate_non_negative_index("n_obs", "B", B);
      current_statement__ = 122;
      context__.validate_dims("data initialization", "n_obs", "int",
        std::vector<size_t>{static_cast<size_t>(B)});
      n_obs = std::vector<int>(B, std::numeric_limits<int>::min());
      current_statement__ = 122;
      n_obs = context__.vals_i("n_obs");
      current_statement__ = 122;
      stan::math::check_greater_or_equal(function__, "n_obs", n_obs, 1);
      current_statement__ = 123;
      context__.validate_dims("data initialization", "total_cells_obs",
        "int", std::vector<size_t>{});
      total_cells_obs = std::numeric_limits<int>::min();
      current_statement__ = 123;
      total_cells_obs = context__.vals_i("total_cells_obs")[(1 - 1)];
      current_statement__ = 123;
      stan::math::check_greater_or_equal(function__, "total_cells_obs",
        total_cells_obs, 1);
      current_statement__ = 124;
      stan::math::validate_non_negative_index("patterns_obs",
        "total_cells_obs", total_cells_obs);
      current_statement__ = 125;
      context__.validate_dims("data initialization", "patterns_obs", "int",
        std::vector<size_t>{static_cast<size_t>(total_cells_obs)});
      patterns_obs = std::vector<int>(total_cells_obs,
                       std::numeric_limits<int>::min());
      current_statement__ = 125;
      patterns_obs = context__.vals_i("patterns_obs");
      current_statement__ = 125;
      stan::math::check_greater_or_equal(function__, "patterns_obs",
        patterns_obs, 1);
      current_statement__ = 126;
      stan::math::validate_non_negative_index("obs_start", "B + 1", (B + 1));
      current_statement__ = 127;
      context__.validate_dims("data initialization", "obs_start", "int",
        std::vector<size_t>{static_cast<size_t>((B + 1))});
      obs_start = std::vector<int>((B + 1), std::numeric_limits<int>::min());
      current_statement__ = 127;
      obs_start = context__.vals_i("obs_start");
      current_statement__ = 127;
      stan::math::check_greater_or_equal(function__, "obs_start", obs_start,
        1);
      current_statement__ = 128;
      stan::math::validate_non_negative_index("fc_len", "B", B);
      current_statement__ = 129;
      context__.validate_dims("data initialization", "fc_len", "int",
        std::vector<size_t>{static_cast<size_t>(B)});
      fc_len = std::vector<int>(B, std::numeric_limits<int>::min());
      current_statement__ = 129;
      fc_len = context__.vals_i("fc_len");
      current_statement__ = 129;
      stan::math::check_greater_or_equal(function__, "fc_len", fc_len, 1);
      current_statement__ = 130;
      context__.validate_dims("data initialization", "a_mu", "double",
        std::vector<size_t>{});
      a_mu = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 130;
      a_mu = context__.vals_r("a_mu")[(1 - 1)];
      current_statement__ = 131;
      context__.validate_dims("data initialization", "a_sigma", "double",
        std::vector<size_t>{});
      a_sigma = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 131;
      a_sigma = context__.vals_r("a_sigma")[(1 - 1)];
      current_statement__ = 131;
      stan::math::check_greater_or_equal(function__, "a_sigma", a_sigma, 0);
      current_statement__ = 132;
      context__.validate_dims("data initialization", "b_mu", "double",
        std::vector<size_t>{});
      b_mu = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 132;
      b_mu = context__.vals_r("b_mu")[(1 - 1)];
      current_statement__ = 133;
      context__.validate_dims("data initialization", "b_sigma", "double",
        std::vector<size_t>{});
      b_sigma = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 133;
      b_sigma = context__.vals_r("b_sigma")[(1 - 1)];
      current_statement__ = 133;
      stan::math::check_greater_or_equal(function__, "b_sigma", b_sigma, 0);
      current_statement__ = 134;
      context__.validate_dims("data initialization", "c_mu", "double",
        std::vector<size_t>{});
      c_mu = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 134;
      c_mu = context__.vals_r("c_mu")[(1 - 1)];
      current_statement__ = 135;
      context__.validate_dims("data initialization", "c_sigma", "double",
        std::vector<size_t>{});
      c_sigma = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 135;
      c_sigma = context__.vals_r("c_sigma")[(1 - 1)];
      current_statement__ = 135;
      stan::math::check_greater_or_equal(function__, "c_sigma", c_sigma, 0);
      current_statement__ = 136;
      context__.validate_dims("data initialization", "d_mu", "double",
        std::vector<size_t>{});
      d_mu = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 136;
      d_mu = context__.vals_r("d_mu")[(1 - 1)];
      current_statement__ = 137;
      context__.validate_dims("data initialization", "d_sigma", "double",
        std::vector<size_t>{});
      d_sigma = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 137;
      d_sigma = context__.vals_r("d_sigma")[(1 - 1)];
      current_statement__ = 137;
      stan::math::check_greater_or_equal(function__, "d_sigma", d_sigma, 0);
      current_statement__ = 138;
      stan::math::validate_non_negative_index("theta_mu", "D", D);
      current_statement__ = 139;
      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__ = 139;
        theta_mu_flat__ = context__.vals_r("theta_mu");
        current_statement__ = 139;
        pos__ = 1;
        current_statement__ = 139;
        for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
          current_statement__ = 139;
          stan::model::assign(theta_mu, theta_mu_flat__[(pos__ - 1)],
            "assigning variable theta_mu", stan::model::index_uni(sym1__));
          current_statement__ = 139;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 140;
      a_free_size = std::numeric_limits<int>::min();
      current_statement__ = 140;
      a_free_size = 0;
      current_statement__ = 141;
      b_free_size = std::numeric_limits<int>::min();
      current_statement__ = 141;
      b_free_size = (I - B);
      current_statement__ = 142;
      c_size = std::numeric_limits<int>::min();
      current_statement__ = 142;
      c_size = 0;
      current_statement__ = 143;
      d_size = std::numeric_limits<int>::min();
      current_statement__ = 143;
      d_size = 0;
      current_statement__ = 152;
      if (stan::math::logical_gte(model_type, 2)) {
        current_statement__ = 150;
        for (int i = 1; i <= I; ++i) {
          current_statement__ = 148;
          for (int j = 1; j <= D; ++j) {
            current_statement__ = 146;
            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__ = 144;
              a_free_size = (a_free_size + 1);
            }
          }
        }
      }
      current_statement__ = 155;
      if (stan::math::logical_gte(model_type, 3)) {
        current_statement__ = 153;
        c_size = I;
      }
      current_statement__ = 158;
      if (stan::math::logical_eq(model_type, 4)) {
        current_statement__ = 156;
        d_size = I;
      }
      current_statement__ = 159;
      stan::math::validate_non_negative_index("a_free", "a_free_size",
        a_free_size);
      current_statement__ = 160;
      stan::math::validate_non_negative_index("b_free", "b_free_size",
        b_free_size);
      current_statement__ = 161;
      stan::math::validate_non_negative_index("c", "c_size", c_size);
      current_statement__ = 162;
      stan::math::validate_non_negative_index("d", "d_size", d_size);
      current_statement__ = 163;
      L_Corr_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 163;
      L_Corr_1dim__ = (stan::math::logical_gt(D, 1) ? D : 2);
      current_statement__ = 163;
      stan::math::validate_non_negative_index("L_Corr", "D > 1 ? D : 2",
        L_Corr_1dim__);
      current_statement__ = 163;
      L_Corr_2dim__ = std::numeric_limits<int>::min();
      current_statement__ = 163;
      L_Corr_2dim__ = (stan::math::logical_gt(D, 1) ? D : 2);
      current_statement__ = 163;
      stan::math::validate_non_negative_index("L_Corr", "D > 1 ? D : 2",
        L_Corr_2dim__);
      current_statement__ = 164;
      stan::math::validate_non_negative_index("theta_raw", "N", N);
      current_statement__ = 165;
      stan::math::validate_non_negative_index("theta_raw", "D", D);
      current_statement__ = 166;
      stan::math::validate_non_negative_index("a", "I", I);
      current_statement__ = 167;
      stan::math::validate_non_negative_index("a", "D", D);
      current_statement__ = 168;
      stan::math::validate_non_negative_index("b", "I", I);
      current_statement__ = 169;
      stan::math::validate_non_negative_index("c_full", "I", I);
      current_statement__ = 170;
      stan::math::validate_non_negative_index("d_full", "I", I);
      current_statement__ = 171;
      stan::math::validate_non_negative_index("theta", "N", N);
      current_statement__ = 172;
      stan::math::validate_non_negative_index("theta", "D", D);
      current_statement__ = 173;
      stan::math::validate_non_negative_index("Corr", "D", D);
      current_statement__ = 174;
      stan::math::validate_non_negative_index("Corr", "D", D);
      current_statement__ = 175;
      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 + b_free_size + c_size + d_size +
      ((L_Corr_1dim__ * (L_Corr_1dim__ - 1)) / 2) + (N * D);
  }
  inline std::string model_name() const final {
    return "model_FCMIRT";
  }
  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_FCMIRT_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_free =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(b_free_size,
          DUMMY_VAR__);
      current_statement__ = 2;
      b_free = in__.template read<
                 Eigen::Matrix<local_scalar_t__,-1,1>>(b_free_size);
      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> b =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(I, DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> c_full =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(I, DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> d_full =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(I, DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,-1> theta =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(N, D, 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,
              stan::model::rvalue(Q_matrix, "Q_matrix",
                stan::model::index_uni(i), stan::model::index_uni(j)),
              "assigning variable a", stan::model::index_uni(i),
              stan::model::index_uni(j));
          }
        }
      } else {
        int idx = std::numeric_limits<int>::min();
        current_statement__ = 14;
        idx = 1;
        current_statement__ = 24;
        for (int i = 1; i <= I; ++i) {
          current_statement__ = 22;
          for (int j = 1; j <= D; ++j) {
            current_statement__ = 20;
            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__ = 17;
              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__ = 18;
              idx = (idx + 1);
            } else {
              current_statement__ = 15;
              stan::model::assign(a, 0.0, "assigning variable a",
                stan::model::index_uni(i), stan::model::index_uni(j));
            }
          }
        }
      }
      {
        int idx = std::numeric_limits<int>::min();
        current_statement__ = 33;
        idx = 1;
        current_statement__ = 44;
        for (int blk = 1; blk <= B; ++blk) {
          int K = std::numeric_limits<int>::min();
          current_statement__ = 34;
          K = stan::model::rvalue(n_items, "n_items",
                stan::model::index_uni(blk));
          local_scalar_t__ b_sum = DUMMY_VAR__;
          current_statement__ = 35;
          b_sum = 0.0;
          current_statement__ = 41;
          for (int k = 1; k <= (K - 1); ++k) {
            int gi = std::numeric_limits<int>::min();
            current_statement__ = 36;
            gi = stan::model::rvalue(block_items, "block_items",
                   stan::model::index_uni(
                     ((stan::model::rvalue(item_start, "item_start",
                         stan::model::index_uni(blk)) + k) - 1)));
            current_statement__ = 37;
            stan::model::assign(b,
              stan::model::rvalue(b_free, "b_free",
                stan::model::index_uni(idx)), "assigning variable b",
              stan::model::index_uni(gi));
            current_statement__ = 38;
            b_sum = (b_sum +
              stan::model::rvalue(b_free, "b_free",
                stan::model::index_uni(idx)));
            current_statement__ = 39;
            idx = (idx + 1);
          }
          current_statement__ = 42;
          stan::model::assign(b, -b_sum, "assigning variable b",
            stan::model::index_uni(
              stan::model::rvalue(block_items, "block_items",
                stan::model::index_uni(
                  ((stan::model::rvalue(item_start, "item_start",
                      stan::model::index_uni(blk)) + K) - 1)))));
        }
      }
      current_statement__ = 50;
      if (stan::math::logical_gte(model_type, 3)) {
        current_statement__ = 48;
        stan::model::assign(c_full, c, "assigning variable c_full");
      } else {
        current_statement__ = 46;
        stan::model::assign(c_full, stan::math::rep_vector(0.0, I),
          "assigning variable c_full");
      }
      current_statement__ = 55;
      if (stan::math::logical_eq(model_type, 4)) {
        current_statement__ = 53;
        stan::model::assign(d_full, d, "assigning variable d_full");
      } else {
        current_statement__ = 51;
        stan::model::assign(d_full, stan::math::rep_vector(1.0, I),
          "assigning variable d_full");
      }
      current_statement__ = 62;
      for (int n = 1; n <= N; ++n) {
        current_statement__ = 60;
        if (stan::math::logical_gt(D, 1)) {
          current_statement__ = 58;
          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__ = 56;
          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__ = 7;
      stan::math::check_greater_or_equal(function__, "a", a, 0);
      {
        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__ = 89;
        for (int obs = 1; obs <= N_obs; ++obs) {
          current_statement__ = 87;
          lp_accum__.add(fcmirt_obs_ll(
                           stan::model::rvalue(pid, "pid",
                             stan::model::index_uni(obs)),
                           stan::model::rvalue(bid, "bid",
                             stan::model::index_uni(obs)),
                           stan::model::rvalue(y, "y",
                             stan::model::index_uni(obs)), model_type, theta,
                           a, b, c_full, d_full, n_items, fc_type,
                           block_items, item_start, n_total, patterns_total,
                           total_start, patterns_obs, obs_start, fc_len,
                           pstream__));
        }
      }
    } 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_FCMIRT_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_free =
        Eigen::Matrix<double,-1,1>::Constant(b_free_size,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 2;
      b_free = in__.template read<
                 Eigen::Matrix<local_scalar_t__,-1,1>>(b_free_size);
      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> b =
        Eigen::Matrix<double,-1,1>::Constant(I,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> c_full =
        Eigen::Matrix<double,-1,1>::Constant(I,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> d_full =
        Eigen::Matrix<double,-1,1>::Constant(I,
          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());
      out__.write(a_free);
      out__.write(b_free);
      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,
              stan::model::rvalue(Q_matrix, "Q_matrix",
                stan::model::index_uni(i), stan::model::index_uni(j)),
              "assigning variable a", stan::model::index_uni(i),
              stan::model::index_uni(j));
          }
        }
      } else {
        int idx = std::numeric_limits<int>::min();
        current_statement__ = 14;
        idx = 1;
        current_statement__ = 24;
        for (int i = 1; i <= I; ++i) {
          current_statement__ = 22;
          for (int j = 1; j <= D; ++j) {
            current_statement__ = 20;
            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__ = 17;
              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__ = 18;
              idx = (idx + 1);
            } else {
              current_statement__ = 15;
              stan::model::assign(a, 0.0, "assigning variable a",
                stan::model::index_uni(i), stan::model::index_uni(j));
            }
          }
        }
      }
      {
        int idx = std::numeric_limits<int>::min();
        current_statement__ = 33;
        idx = 1;
        current_statement__ = 44;
        for (int blk = 1; blk <= B; ++blk) {
          int K = std::numeric_limits<int>::min();
          current_statement__ = 34;
          K = stan::model::rvalue(n_items, "n_items",
                stan::model::index_uni(blk));
          double b_sum = std::numeric_limits<double>::quiet_NaN();
          current_statement__ = 35;
          b_sum = 0.0;
          current_statement__ = 41;
          for (int k = 1; k <= (K - 1); ++k) {
            int gi = std::numeric_limits<int>::min();
            current_statement__ = 36;
            gi = stan::model::rvalue(block_items, "block_items",
                   stan::model::index_uni(
                     ((stan::model::rvalue(item_start, "item_start",
                         stan::model::index_uni(blk)) + k) - 1)));
            current_statement__ = 37;
            stan::model::assign(b,
              stan::model::rvalue(b_free, "b_free",
                stan::model::index_uni(idx)), "assigning variable b",
              stan::model::index_uni(gi));
            current_statement__ = 38;
            b_sum = (b_sum +
              stan::model::rvalue(b_free, "b_free",
                stan::model::index_uni(idx)));
            current_statement__ = 39;
            idx = (idx + 1);
          }
          current_statement__ = 42;
          stan::model::assign(b, -b_sum, "assigning variable b",
            stan::model::index_uni(
              stan::model::rvalue(block_items, "block_items",
                stan::model::index_uni(
                  ((stan::model::rvalue(item_start, "item_start",
                      stan::model::index_uni(blk)) + K) - 1)))));
        }
      }
      current_statement__ = 50;
      if (stan::math::logical_gte(model_type, 3)) {
        current_statement__ = 48;
        stan::model::assign(c_full, c, "assigning variable c_full");
      } else {
        current_statement__ = 46;
        stan::model::assign(c_full, stan::math::rep_vector(0.0, I),
          "assigning variable c_full");
      }
      current_statement__ = 55;
      if (stan::math::logical_eq(model_type, 4)) {
        current_statement__ = 53;
        stan::model::assign(d_full, d, "assigning variable d_full");
      } else {
        current_statement__ = 51;
        stan::model::assign(d_full, stan::math::rep_vector(1.0, I),
          "assigning variable d_full");
      }
      current_statement__ = 62;
      for (int n = 1; n <= N; ++n) {
        current_statement__ = 60;
        if (stan::math::logical_gt(D, 1)) {
          current_statement__ = 58;
          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__ = 56;
          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__ = 7;
      stan::math::check_greater_or_equal(function__, "a", a, 0);
      if (emit_transformed_parameters__) {
        out__.write(a);
        out__.write(b);
        out__.write(c_full);
        out__.write(d_full);
        out__.write(theta);
      }
      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__ = 67;
      if (stan::math::logical_gt(D, 1)) {
        current_statement__ = 65;
        stan::model::assign(Corr,
          stan::math::multiply_lower_tri_self_transpose(L_Corr),
          "assigning variable Corr");
      } else {
        current_statement__ = 63;
        stan::model::assign(Corr, 1.0, "assigning variable Corr",
          stan::model::index_uni(1), stan::model::index_uni(1));
      }
      current_statement__ = 70;
      for (int obs = 1; obs <= N_obs; ++obs) {
        current_statement__ = 68;
        stan::model::assign(log_lik,
          fcmirt_obs_ll(
            stan::model::rvalue(pid, "pid", stan::model::index_uni(obs)),
            stan::model::rvalue(bid, "bid", stan::model::index_uni(obs)),
            stan::model::rvalue(y, "y", stan::model::index_uni(obs)),
            model_type, theta, a, b, c_full, d_full, n_items, fc_type,
            block_items, item_start, n_total, patterns_total, total_start,
            patterns_obs, obs_start, fc_len, pstream__),
          "assigning variable log_lik", stan::model::index_uni(obs));
      }
      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_free =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(b_free_size,
          DUMMY_VAR__);
      current_statement__ = 2;
      stan::model::assign(b_free,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(b_free_size),
        "assigning variable b_free");
      out__.write(b_free);
      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_free", "double",
        std::vector<size_t>{static_cast<size_t>(b_free_size)});
      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_free =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(b_free_size,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> b_free_flat__;
        current_statement__ = 2;
        b_free_flat__ = context__.vals_r("b_free");
        current_statement__ = 2;
        pos__ = 1;
        current_statement__ = 2;
        for (int sym1__ = 1; sym1__ <= b_free_size; ++sym1__) {
          current_statement__ = 2;
          stan::model::assign(b_free, b_free_flat__[(pos__ - 1)],
            "assigning variable b_free", stan::model::index_uni(sym1__));
          current_statement__ = 2;
          pos__ = (pos__ + 1);
        }
      }
      out__.write(b_free);
      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_free", "c", "d",
                "L_Corr", "theta_raw"};
    if (emit_transformed_parameters__) {
      std::vector<std::string> temp{"a", "b", "c_full", "d_full", "theta"};
      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>(b_free_size)},
                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>(I)},
             std::vector<size_t>{static_cast<size_t>(I)},
             std::vector<size_t>{static_cast<size_t>(I)},
             std::vector<size_t>{static_cast<size_t>(N),
               static_cast<size_t>(D)}};
      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__ <= b_free_size; ++sym1__) {
      param_names__.emplace_back(std::string() + "b_free" + '.' +
        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__ <= I; ++sym1__) {
        param_names__.emplace_back(std::string() + "b" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= I; ++sym1__) {
        param_names__.emplace_back(std::string() + "c_full" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= I; ++sym1__) {
        param_names__.emplace_back(std::string() + "d_full" + '.' +
          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__));
        }
      }
    }
    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__ <= b_free_size; ++sym1__) {
      param_names__.emplace_back(std::string() + "b_free" + '.' +
        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__ <= I; ++sym1__) {
        param_names__.emplace_back(std::string() + "b" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= I; ++sym1__) {
        param_names__.emplace_back(std::string() + "c_full" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= I; ++sym1__) {
        param_names__.emplace_back(std::string() + "d_full" + '.' +
          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__));
        }
      }
    }
    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_free\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(b_free_size) + "},\"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\":\"b\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(I) + "},\"block\":\"transformed_parameters\"},{\"name\":\"c_full\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(I) + "},\"block\":\"transformed_parameters\"},{\"name\":\"d_full\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(I) + "},\"block\":\"transformed_parameters\"},{\"name\":\"theta\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(N) + ",\"cols\":" + std::to_string(D) + "},\"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_free\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(b_free_size) + "},\"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\":\"b\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(I) + "},\"block\":\"transformed_parameters\"},{\"name\":\"c_full\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(I) + "},\"block\":\"transformed_parameters\"},{\"name\":\"d_full\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(I) + "},\"block\":\"transformed_parameters\"},{\"name\":\"theta\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(N) + ",\"cols\":" + std::to_string(D) + "},\"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 + b_free_size) + c_size) +
      d_size) + (L_Corr_1dim__ * L_Corr_2dim__)) + (N * D));
    const size_t num_transformed = emit_transformed_parameters * ((((((I * D)
      + I) + I) + I) + (N * D)));
    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 + b_free_size) + c_size) +
      d_size) + (L_Corr_1dim__ * L_Corr_2dim__)) + (N * D));
    const size_t num_transformed = emit_transformed_parameters * ((((((I * D)
      + I) + I) + I) + (N * D)));
    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_FCMIRT_namespace::model_FCMIRT;
#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_FCMIRT_namespace::profiles__;
}
#endif
#endif
