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

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

    SteadyStateBVAR 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 SteadyStateBVAR.  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_steady_state_bvar_homoscedastic_inverse_wishart_prior_namespace {
using stan::model::model_base_crtp;
using namespace stan::math;
stan::math::profile_map profiles__;
static constexpr std::array<const char*, 107> locations_array__ =
  {" (found before start of program)",
  " (in 'string', line 50, column 2 to column 22)",
  " (in 'string', line 51, column 2 to column 19)",
  " (in 'string', line 52, column 2 to column 24)",
  " (in 'string', line 64, column 2 to column 21)",
  " (in 'string', line 68, column 2 to column 22)",
  " (in 'string', line 66, column 4 to column 50)",
  " (in 'string', line 65, column 17 to line 67, column 3)",
  " (in 'string', line 65, column 2 to line 67, column 3)",
  " (in 'string', line 70, column 11 to column 12)",
  " (in 'string', line 70, column 4 to column 64)",
  " (in 'string', line 71, column 11 to column 12)",
  " (in 'string', line 71, column 4 to column 41)",
  " (in 'string', line 74, column 8 to column 71)",
  " (in 'string', line 73, column 31 to line 75, column 7)",
  " (in 'string', line 73, column 6 to line 75, column 7)",
  " (in 'string', line 72, column 15 to line 76, column 5)",
  " (in 'string', line 72, column 4 to line 76, column 5)",
  " (in 'string', line 79, column 8 to column 73)",
  " (in 'string', line 78, column 21 to line 80, column 7)",
  " (in 'string', line 78, column 6 to line 80, column 7)",
  " (in 'string', line 77, column 16 to line 81, column 5)",
  " (in 'string', line 77, column 4 to line 81, column 5)",
  " (in 'string', line 82, column 4 to column 32)",
  " (in 'string', line 69, column 17 to line 83, column 3)",
  " (in 'string', line 69, column 2 to line 83, column 3)",
  " (in 'string', line 56, column 13 to column 14)",
  " (in 'string', line 56, column 6 to column 80)",
  " (in 'string', line 57, column 6 to column 51)",
  " (in 'string', line 55, column 15 to line 58, column 3)",
  " (in 'string', line 55, column 2 to line 58, column 3)",
  " (in 'string', line 59, column 2 to column 57)",
  " (in 'string', line 60, column 2 to column 54)",
  " (in 'string', line 61, column 2 to column 30)",
  " (in 'string', line 29, column 2 to column 17)",
  " (in 'string', line 30, column 2 to column 19)",
  " (in 'string', line 31, column 2 to column 17)",
  " (in 'string', line 32, column 2 to column 17)",
  " (in 'string', line 33, column 9 to column 10)",
  " (in 'string', line 33, column 12 to column 13)",
  " (in 'string', line 33, column 2 to column 17)",
  " (in 'string', line 34, column 9 to column 10)",
  " (in 'string', line 34, column 12 to column 13)",
  " (in 'string', line 34, column 2 to column 17)",
  " (in 'string', line 35, column 9 to column 10)",
  " (in 'string', line 35, column 12 to column 15)",
  " (in 'string', line 35, column 2 to column 19)",
  " (in 'string', line 36, column 9 to column 10)",
  " (in 'string', line 36, column 12 to column 15)",
  " (in 'string', line 36, column 2 to column 19)",
  " (in 'string', line 37, column 9 to column 14)",
  " (in 'string', line 37, column 2 to column 27)",
  " (in 'string', line 38, column 9 to column 14)",
  " (in 'string', line 38, column 16 to column 21)",
  " (in 'string', line 38, column 2 to column 34)",
  " (in 'string', line 39, column 9 to column 12)",
  " (in 'string', line 39, column 2 to column 24)",
  " (in 'string', line 40, column 9 to column 12)",
  " (in 'string', line 40, column 14 to column 17)",
  " (in 'string', line 40, column 2 to column 29)",
  " (in 'string', line 41, column 2 to column 19)",
  " (in 'string', line 42, column 9 to column 10)",
  " (in 'string', line 42, column 12 to column 13)",
  " (in 'string', line 42, column 2 to column 17)",
  " (in 'string', line 43, column 2 to column 17)",
  " (in 'string', line 44, column 9 to column 10)",
  " (in 'string', line 44, column 12 to column 13)",
  " (in 'string', line 44, column 2 to column 22)",
  " (in 'string', line 47, column 11 to column 12)",
  " (in 'string', line 47, column 14 to column 15)",
  " (in 'string', line 47, column 4 to column 53)",
  " (in 'string', line 50, column 9 to column 12)",
  " (in 'string', line 50, column 14 to column 15)",
  " (in 'string', line 51, column 9 to column 10)",
  " (in 'string', line 51, column 12 to column 13)",
  " (in 'string', line 52, column 13 to column 14)",
  " (in 'string', line 64, column 18 to column 19)",
  " (in 'string', line 64, column 9 to column 10)",
  " (in 'string', line 64, column 12 to column 13)",
  " (in 'string', line 68, column 9 to column 10)",
  " (in 'string', line 68, column 12 to column 13)",
  " (in 'string', line 3, column 9 to column 26)",
  " (in 'string', line 3, column 28 to column 45)",
  " (in 'string', line 3, column 2 to column 49)",
  " (in 'string', line 4, column 2 to column 8)",
  " (in 'string', line 5, column 2 to column 8)",
  " (in 'string', line 6, column 2 to column 8)",
  " (in 'string', line 7, column 2 to column 8)",
  " (in 'string', line 8, column 2 to column 14)",
  " (in 'string', line 9, column 2 to column 14)",
  " (in 'string', line 10, column 2 to column 14)",
  " (in 'string', line 11, column 2 to column 14)",
  " (in 'string', line 14, column 6 to column 20)",
  " (in 'string', line 15, column 6 to column 18)",
  " (in 'string', line 16, column 6 to column 20)",
  " (in 'string', line 17, column 6 to column 18)",
  " (in 'string', line 18, column 6 to column 34)",
  " (in 'string', line 19, column 6 to column 32)",
  " (in 'string', line 20, column 6 to column 34)",
  " (in 'string', line 21, column 6 to column 32)",
  " (in 'string', line 22, column 6 to column 60)",
  " (in 'string', line 13, column 19 to line 23, column 5)",
  " (in 'string', line 13, column 4 to line 23, column 5)",
  " (in 'string', line 12, column 17 to line 24, column 3)",
  " (in 'string', line 12, column 2 to line 24, column 3)",
  " (in 'string', line 25, column 2 to column 11)",
  " (in 'string', line 2, column 34 to line 26, column 3)"};
template <typename T0__, typename T1__,
          stan::require_all_t<stan::is_eigen_matrix_dynamic<T0__>,
                              stan::is_vt_not_complex<T0__>,
                              stan::is_eigen_matrix_dynamic<T1__>,
                              stan::is_vt_not_complex<T1__>>* = nullptr>
Eigen::Matrix<stan::promote_args_t<stan::base_type_t<T0__>,
                stan::base_type_t<T1__>>,-1,-1>
kron(const T0__& A_arg__, const T1__& B_arg__, std::ostream* pstream__);
template <typename T0__, typename T1__,
          stan::require_all_t<stan::is_eigen_matrix_dynamic<T0__>,
                              stan::is_vt_not_complex<T0__>,
                              stan::is_eigen_matrix_dynamic<T1__>,
                              stan::is_vt_not_complex<T1__>>*>
Eigen::Matrix<stan::promote_args_t<stan::base_type_t<T0__>,
                stan::base_type_t<T1__>>,-1,-1>
kron(const T0__& A_arg__, const T1__& B_arg__, std::ostream* pstream__) {
  using local_scalar_t__ = stan::promote_args_t<stan::base_type_t<T0__>,
                             stan::base_type_t<T1__>>;
  int current_statement__ = 0;
  const auto& A = stan::math::to_ref(A_arg__);
  const auto& B = stan::math::to_ref(B_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 {
    current_statement__ = 81;
    stan::math::validate_non_negative_index("C", "rows(A) * rows(B)",
      (stan::math::rows(A) * stan::math::rows(B)));
    current_statement__ = 82;
    stan::math::validate_non_negative_index("C", "cols(A) * cols(B)",
      (stan::math::cols(A) * stan::math::cols(B)));
    Eigen::Matrix<local_scalar_t__,-1,-1> C =
      Eigen::Matrix<local_scalar_t__,-1,-1>::Constant((stan::math::rows(A) *
        stan::math::rows(B)), (stan::math::cols(A) * stan::math::cols(B)),
        DUMMY_VAR__);
    int m = std::numeric_limits<int>::min();
    int n = std::numeric_limits<int>::min();
    int p = std::numeric_limits<int>::min();
    int q = std::numeric_limits<int>::min();
    current_statement__ = 88;
    m = stan::math::rows(A);
    current_statement__ = 89;
    n = stan::math::cols(A);
    current_statement__ = 90;
    p = stan::math::rows(B);
    current_statement__ = 91;
    q = stan::math::cols(B);
    current_statement__ = 104;
    for (int i = 1; i <= m; ++i) {
      current_statement__ = 102;
      for (int j = 1; j <= n; ++j) {
        int row_start = std::numeric_limits<int>::min();
        int row_end = std::numeric_limits<int>::min();
        int col_start = std::numeric_limits<int>::min();
        int col_end = std::numeric_limits<int>::min();
        current_statement__ = 96;
        row_start = (((i - 1) * p) + 1);
        current_statement__ = 97;
        row_end = (((i - 1) * p) + p);
        current_statement__ = 98;
        col_start = (((j - 1) * q) + 1);
        current_statement__ = 99;
        col_end = (((j - 1) * q) + q);
        current_statement__ = 100;
        stan::model::assign(C,
          stan::math::multiply(
            stan::model::rvalue(A, "A", stan::model::index_uni(i),
              stan::model::index_uni(j)), B), "assigning variable C",
          stan::model::index_min_max(row_start, row_end),
          stan::model::index_min_max(col_start, col_end));
      }
    }
    current_statement__ = 105;
    return C;
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
#include <stan_meta_header.hpp>
class model_steady_state_bvar_homoscedastic_inverse_wishart_prior final : public 
 model_base_crtp<model_steady_state_bvar_homoscedastic_inverse_wishart_prior> {
private:
  int p;
  int N;
  int k;
  int q;
  Eigen::Matrix<double,-1,-1> Y_data__;
  Eigen::Matrix<double,-1,-1> D_data__;
  Eigen::Matrix<double,-1,-1> W_data__;
  Eigen::Matrix<double,-1,-1> Q_data__;
  Eigen::Matrix<double,-1,1> theta_beta_data__;
  Eigen::Matrix<double,-1,-1> Omega_beta_data__;
  Eigen::Matrix<double,-1,1> theta_Psi_data__;
  Eigen::Matrix<double,-1,-1> Omega_Psi_data__;
  int m;
  Eigen::Matrix<double,-1,-1> V_data__;
  int H;
  Eigen::Matrix<double,-1,-1> d_pred_data__;
  Eigen::Matrix<double,-1,-1> I_p_data__;
  int beta_1dim__;
  Eigen::Map<Eigen::Matrix<double,-1,-1>> Y{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> D{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> W{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> Q{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> theta_beta{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> Omega_beta{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> theta_Psi{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> Omega_Psi{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> V{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> d_pred{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> I_p{nullptr, 0, 0};
public:
  ~model_steady_state_bvar_homoscedastic_inverse_wishart_prior() {}
  model_steady_state_bvar_homoscedastic_inverse_wishart_prior(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_steady_state_bvar_homoscedastic_inverse_wishart_prior_namespace::model_steady_state_bvar_homoscedastic_inverse_wishart_prior";
    // 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__ = 34;
      context__.validate_dims("data initialization", "p", "int",
        std::vector<size_t>{});
      p = std::numeric_limits<int>::min();
      current_statement__ = 34;
      p = context__.vals_i("p")[(1 - 1)];
      current_statement__ = 34;
      stan::math::check_greater_or_equal(function__, "p", p, 1);
      current_statement__ = 35;
      context__.validate_dims("data initialization", "N", "int",
        std::vector<size_t>{});
      N = std::numeric_limits<int>::min();
      current_statement__ = 35;
      N = context__.vals_i("N")[(1 - 1)];
      current_statement__ = 35;
      stan::math::check_greater_or_equal(function__, "N", N, (p + 1));
      current_statement__ = 36;
      context__.validate_dims("data initialization", "k", "int",
        std::vector<size_t>{});
      k = std::numeric_limits<int>::min();
      current_statement__ = 36;
      k = context__.vals_i("k")[(1 - 1)];
      current_statement__ = 36;
      stan::math::check_greater_or_equal(function__, "k", k, 2);
      current_statement__ = 37;
      context__.validate_dims("data initialization", "q", "int",
        std::vector<size_t>{});
      q = std::numeric_limits<int>::min();
      current_statement__ = 37;
      q = context__.vals_i("q")[(1 - 1)];
      current_statement__ = 37;
      stan::math::check_greater_or_equal(function__, "q", q, 1);
      current_statement__ = 38;
      stan::math::validate_non_negative_index("Y", "N", N);
      current_statement__ = 39;
      stan::math::validate_non_negative_index("Y", "k", k);
      current_statement__ = 40;
      context__.validate_dims("data initialization", "Y", "double",
        std::vector<size_t>{static_cast<size_t>(N), static_cast<size_t>(k)});
      Y_data__ = Eigen::Matrix<double,-1,-1>::Constant(N, k,
                   std::numeric_limits<double>::quiet_NaN());
      new (&Y) Eigen::Map<Eigen::Matrix<double,-1,-1>>(Y_data__.data(), N, k);
      {
        std::vector<local_scalar_t__> Y_flat__;
        current_statement__ = 40;
        Y_flat__ = context__.vals_r("Y");
        current_statement__ = 40;
        pos__ = 1;
        current_statement__ = 40;
        for (int sym1__ = 1; sym1__ <= k; ++sym1__) {
          current_statement__ = 40;
          for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
            current_statement__ = 40;
            stan::model::assign(Y, Y_flat__[(pos__ - 1)],
              "assigning variable Y", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 40;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 41;
      stan::math::validate_non_negative_index("D", "N", N);
      current_statement__ = 42;
      stan::math::validate_non_negative_index("D", "q", q);
      current_statement__ = 43;
      context__.validate_dims("data initialization", "D", "double",
        std::vector<size_t>{static_cast<size_t>(N), static_cast<size_t>(q)});
      D_data__ = Eigen::Matrix<double,-1,-1>::Constant(N, q,
                   std::numeric_limits<double>::quiet_NaN());
      new (&D) Eigen::Map<Eigen::Matrix<double,-1,-1>>(D_data__.data(), N, q);
      {
        std::vector<local_scalar_t__> D_flat__;
        current_statement__ = 43;
        D_flat__ = context__.vals_r("D");
        current_statement__ = 43;
        pos__ = 1;
        current_statement__ = 43;
        for (int sym1__ = 1; sym1__ <= q; ++sym1__) {
          current_statement__ = 43;
          for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
            current_statement__ = 43;
            stan::model::assign(D, D_flat__[(pos__ - 1)],
              "assigning variable D", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 43;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 44;
      stan::math::validate_non_negative_index("W", "N", N);
      current_statement__ = 45;
      stan::math::validate_non_negative_index("W", "k * p", (k * p));
      current_statement__ = 46;
      context__.validate_dims("data initialization", "W", "double",
        std::vector<size_t>{static_cast<size_t>(N),
          static_cast<size_t>((k * p))});
      W_data__ = Eigen::Matrix<double,-1,-1>::Constant(N, (k * p),
                   std::numeric_limits<double>::quiet_NaN());
      new (&W) Eigen::Map<Eigen::Matrix<double,-1,-1>>(W_data__.data(), N, (k
        * p));
      {
        std::vector<local_scalar_t__> W_flat__;
        current_statement__ = 46;
        W_flat__ = context__.vals_r("W");
        current_statement__ = 46;
        pos__ = 1;
        current_statement__ = 46;
        for (int sym1__ = 1; sym1__ <= (k * p); ++sym1__) {
          current_statement__ = 46;
          for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
            current_statement__ = 46;
            stan::model::assign(W, W_flat__[(pos__ - 1)],
              "assigning variable W", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 46;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 47;
      stan::math::validate_non_negative_index("Q", "N", N);
      current_statement__ = 48;
      stan::math::validate_non_negative_index("Q", "q * p", (q * p));
      current_statement__ = 49;
      context__.validate_dims("data initialization", "Q", "double",
        std::vector<size_t>{static_cast<size_t>(N),
          static_cast<size_t>((q * p))});
      Q_data__ = Eigen::Matrix<double,-1,-1>::Constant(N, (q * p),
                   std::numeric_limits<double>::quiet_NaN());
      new (&Q) Eigen::Map<Eigen::Matrix<double,-1,-1>>(Q_data__.data(), N, (q
        * p));
      {
        std::vector<local_scalar_t__> Q_flat__;
        current_statement__ = 49;
        Q_flat__ = context__.vals_r("Q");
        current_statement__ = 49;
        pos__ = 1;
        current_statement__ = 49;
        for (int sym1__ = 1; sym1__ <= (q * p); ++sym1__) {
          current_statement__ = 49;
          for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
            current_statement__ = 49;
            stan::model::assign(Q, Q_flat__[(pos__ - 1)],
              "assigning variable Q", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 49;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 50;
      stan::math::validate_non_negative_index("theta_beta", "k * p * k", ((k
        * p) * k));
      current_statement__ = 51;
      context__.validate_dims("data initialization", "theta_beta", "double",
        std::vector<size_t>{static_cast<size_t>(((k * p) * k))});
      theta_beta_data__ = Eigen::Matrix<double,-1,1>::Constant(((k * p) * k),
                            std::numeric_limits<double>::quiet_NaN());
      new (&theta_beta)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(theta_beta_data__.data(), ((k
        * p) * k));
      {
        std::vector<local_scalar_t__> theta_beta_flat__;
        current_statement__ = 51;
        theta_beta_flat__ = context__.vals_r("theta_beta");
        current_statement__ = 51;
        pos__ = 1;
        current_statement__ = 51;
        for (int sym1__ = 1; sym1__ <= ((k * p) * k); ++sym1__) {
          current_statement__ = 51;
          stan::model::assign(theta_beta, theta_beta_flat__[(pos__ - 1)],
            "assigning variable theta_beta", stan::model::index_uni(sym1__));
          current_statement__ = 51;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 52;
      stan::math::validate_non_negative_index("Omega_beta", "k * p * k", ((k
        * p) * k));
      current_statement__ = 53;
      stan::math::validate_non_negative_index("Omega_beta", "k * p * k", ((k
        * p) * k));
      current_statement__ = 54;
      context__.validate_dims("data initialization", "Omega_beta", "double",
        std::vector<size_t>{static_cast<size_t>(((k * p) * k)),
          static_cast<size_t>(((k * p) * k))});
      Omega_beta_data__ = Eigen::Matrix<double,-1,-1>::Constant(((k * p) *
                            k), ((k * p) * k),
                            std::numeric_limits<double>::quiet_NaN());
      new (&Omega_beta)
        Eigen::Map<Eigen::Matrix<double,-1,-1>>(Omega_beta_data__.data(), ((k
        * p) * k), ((k * p) * k));
      {
        std::vector<local_scalar_t__> Omega_beta_flat__;
        current_statement__ = 54;
        Omega_beta_flat__ = context__.vals_r("Omega_beta");
        current_statement__ = 54;
        pos__ = 1;
        current_statement__ = 54;
        for (int sym1__ = 1; sym1__ <= ((k * p) * k); ++sym1__) {
          current_statement__ = 54;
          for (int sym2__ = 1; sym2__ <= ((k * p) * k); ++sym2__) {
            current_statement__ = 54;
            stan::model::assign(Omega_beta, Omega_beta_flat__[(pos__ - 1)],
              "assigning variable Omega_beta",
              stan::model::index_uni(sym2__), stan::model::index_uni(sym1__));
            current_statement__ = 54;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 55;
      stan::math::validate_non_negative_index("theta_Psi", "k * q", (k * q));
      current_statement__ = 56;
      context__.validate_dims("data initialization", "theta_Psi", "double",
        std::vector<size_t>{static_cast<size_t>((k * q))});
      theta_Psi_data__ = Eigen::Matrix<double,-1,1>::Constant((k * q),
                           std::numeric_limits<double>::quiet_NaN());
      new (&theta_Psi)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(theta_Psi_data__.data(), (k *
        q));
      {
        std::vector<local_scalar_t__> theta_Psi_flat__;
        current_statement__ = 56;
        theta_Psi_flat__ = context__.vals_r("theta_Psi");
        current_statement__ = 56;
        pos__ = 1;
        current_statement__ = 56;
        for (int sym1__ = 1; sym1__ <= (k * q); ++sym1__) {
          current_statement__ = 56;
          stan::model::assign(theta_Psi, theta_Psi_flat__[(pos__ - 1)],
            "assigning variable theta_Psi", stan::model::index_uni(sym1__));
          current_statement__ = 56;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 57;
      stan::math::validate_non_negative_index("Omega_Psi", "k * q", (k * q));
      current_statement__ = 58;
      stan::math::validate_non_negative_index("Omega_Psi", "k * q", (k * q));
      current_statement__ = 59;
      context__.validate_dims("data initialization", "Omega_Psi", "double",
        std::vector<size_t>{static_cast<size_t>((k * q)),
          static_cast<size_t>((k * q))});
      Omega_Psi_data__ = Eigen::Matrix<double,-1,-1>::Constant((k * q), (k *
                           q), std::numeric_limits<double>::quiet_NaN());
      new (&Omega_Psi)
        Eigen::Map<Eigen::Matrix<double,-1,-1>>(Omega_Psi_data__.data(), (k *
        q), (k * q));
      {
        std::vector<local_scalar_t__> Omega_Psi_flat__;
        current_statement__ = 59;
        Omega_Psi_flat__ = context__.vals_r("Omega_Psi");
        current_statement__ = 59;
        pos__ = 1;
        current_statement__ = 59;
        for (int sym1__ = 1; sym1__ <= (k * q); ++sym1__) {
          current_statement__ = 59;
          for (int sym2__ = 1; sym2__ <= (k * q); ++sym2__) {
            current_statement__ = 59;
            stan::model::assign(Omega_Psi, Omega_Psi_flat__[(pos__ - 1)],
              "assigning variable Omega_Psi", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 59;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 60;
      context__.validate_dims("data initialization", "m", "int",
        std::vector<size_t>{});
      m = std::numeric_limits<int>::min();
      current_statement__ = 60;
      m = context__.vals_i("m")[(1 - 1)];
      current_statement__ = 60;
      stan::math::check_greater_or_equal(function__, "m", m, (k + 2));
      current_statement__ = 61;
      stan::math::validate_non_negative_index("V", "k", k);
      current_statement__ = 62;
      stan::math::validate_non_negative_index("V", "k", k);
      current_statement__ = 63;
      context__.validate_dims("data initialization", "V", "double",
        std::vector<size_t>{static_cast<size_t>(k), static_cast<size_t>(k)});
      V_data__ = Eigen::Matrix<double,-1,-1>::Constant(k, k,
                   std::numeric_limits<double>::quiet_NaN());
      new (&V) Eigen::Map<Eigen::Matrix<double,-1,-1>>(V_data__.data(), k, k);
      {
        std::vector<local_scalar_t__> V_flat__;
        current_statement__ = 63;
        V_flat__ = context__.vals_r("V");
        current_statement__ = 63;
        pos__ = 1;
        current_statement__ = 63;
        for (int sym1__ = 1; sym1__ <= k; ++sym1__) {
          current_statement__ = 63;
          for (int sym2__ = 1; sym2__ <= k; ++sym2__) {
            current_statement__ = 63;
            stan::model::assign(V, V_flat__[(pos__ - 1)],
              "assigning variable V", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 63;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 64;
      context__.validate_dims("data initialization", "H", "int",
        std::vector<size_t>{});
      H = std::numeric_limits<int>::min();
      current_statement__ = 64;
      H = context__.vals_i("H")[(1 - 1)];
      current_statement__ = 64;
      stan::math::check_greater_or_equal(function__, "H", H, 1);
      current_statement__ = 65;
      stan::math::validate_non_negative_index("d_pred", "H", H);
      current_statement__ = 66;
      stan::math::validate_non_negative_index("d_pred", "q", q);
      current_statement__ = 67;
      context__.validate_dims("data initialization", "d_pred", "double",
        std::vector<size_t>{static_cast<size_t>(H), static_cast<size_t>(q)});
      d_pred_data__ = Eigen::Matrix<double,-1,-1>::Constant(H, q,
                        std::numeric_limits<double>::quiet_NaN());
      new (&d_pred)
        Eigen::Map<Eigen::Matrix<double,-1,-1>>(d_pred_data__.data(), H, q);
      {
        std::vector<local_scalar_t__> d_pred_flat__;
        current_statement__ = 67;
        d_pred_flat__ = context__.vals_r("d_pred");
        current_statement__ = 67;
        pos__ = 1;
        current_statement__ = 67;
        for (int sym1__ = 1; sym1__ <= q; ++sym1__) {
          current_statement__ = 67;
          for (int sym2__ = 1; sym2__ <= H; ++sym2__) {
            current_statement__ = 67;
            stan::model::assign(d_pred, d_pred_flat__[(pos__ - 1)],
              "assigning variable d_pred", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 67;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 68;
      stan::math::validate_non_negative_index("I_p", "p", p);
      current_statement__ = 69;
      stan::math::validate_non_negative_index("I_p", "p", p);
      current_statement__ = 70;
      I_p_data__ = Eigen::Matrix<double,-1,-1>::Constant(p, p,
                     std::numeric_limits<double>::quiet_NaN());
      new (&I_p) Eigen::Map<Eigen::Matrix<double,-1,-1>>(I_p_data__.data(),
        p, p);
      current_statement__ = 70;
      stan::model::assign(I_p,
        stan::math::diag_matrix(stan::math::rep_vector(1, p)),
        "assigning variable I_p");
      current_statement__ = 71;
      beta_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 71;
      beta_1dim__ = (k * p);
      current_statement__ = 71;
      stan::math::validate_non_negative_index("beta", "k * p", beta_1dim__);
      current_statement__ = 72;
      stan::math::validate_non_negative_index("beta", "k", k);
      current_statement__ = 73;
      stan::math::validate_non_negative_index("Psi", "k", k);
      current_statement__ = 74;
      stan::math::validate_non_negative_index("Psi", "q", q);
      current_statement__ = 75;
      stan::math::validate_non_negative_index("Sigma_u", "k", k);
      current_statement__ = 75;
      stan::math::validate_non_negative_index("Sigma_u", "k", k);
      current_statement__ = 76;
      stan::math::validate_non_negative_index("Pi", "p", p);
      current_statement__ = 77;
      stan::math::validate_non_negative_index("Pi", "k", k);
      current_statement__ = 78;
      stan::math::validate_non_negative_index("Pi", "k", k);
      current_statement__ = 79;
      stan::math::validate_non_negative_index("y_pred", "H", H);
      current_statement__ = 80;
      stan::math::validate_non_negative_index("y_pred", "k", k);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
    num_params_r__ = (beta_1dim__ * k) + (k * q) + (k + ((k * (k - 1)) / 2));
  }
  inline std::string model_name() const final {
    return "model_steady_state_bvar_homoscedastic_inverse_wishart_prior";
  }
  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_steady_state_bvar_homoscedastic_inverse_wishart_prior_namespace::log_prob";
    // suppress unused var warning
    (void) function__;
    try {
      Eigen::Matrix<local_scalar_t__,-1,-1> beta =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(beta_1dim__, k,
          DUMMY_VAR__);
      current_statement__ = 1;
      beta = in__.template read<
               Eigen::Matrix<local_scalar_t__,-1,-1>>(beta_1dim__, k);
      Eigen::Matrix<local_scalar_t__,-1,-1> Psi =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(k, q, DUMMY_VAR__);
      current_statement__ = 2;
      Psi = in__.template read<Eigen::Matrix<local_scalar_t__,-1,-1>>(k, q);
      Eigen::Matrix<local_scalar_t__,-1,-1> Sigma_u =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(k, k, DUMMY_VAR__);
      current_statement__ = 3;
      Sigma_u = in__.template read_constrain_cov_matrix<
                  Eigen::Matrix<local_scalar_t__,-1,-1>, jacobian__>(lp__, k);
      {
        current_statement__ = 30;
        for (int t = 1; t <= N; ++t) {
          current_statement__ = 26;
          stan::math::validate_non_negative_index("u_t", "k", k);
          Eigen::Matrix<local_scalar_t__,-1,1> u_t =
            Eigen::Matrix<local_scalar_t__,-1,1>::Constant(k, DUMMY_VAR__);
          current_statement__ = 27;
          stan::model::assign(u_t,
            stan::math::transpose(
              stan::math::subtract(
                stan::model::rvalue(Y, "Y", stan::model::index_uni(t)),
                stan::math::add(
                  stan::math::multiply(
                    stan::model::rvalue(D, "D", stan::model::index_uni(t)),
                    stan::math::transpose(Psi)),
                  stan::math::multiply(
                    stan::math::subtract(
                      stan::model::rvalue(W, "W", stan::model::index_uni(t)),
                      stan::math::multiply(
                        stan::model::rvalue(Q, "Q", stan::model::index_uni(t)),
                        kron(I_p, stan::math::transpose(Psi), pstream__))),
                    beta)))), "assigning variable u_t");
          current_statement__ = 28;
          lp_accum__.add(stan::math::multi_normal_lpdf<propto__>(u_t,
                           stan::math::rep_vector(0, k), Sigma_u));
        }
        current_statement__ = 31;
        lp_accum__.add(stan::math::multi_normal_lpdf<propto__>(
                         stan::math::to_vector(beta), theta_beta, Omega_beta));
        current_statement__ = 32;
        lp_accum__.add(stan::math::multi_normal_lpdf<propto__>(
                         stan::math::to_vector(Psi), theta_Psi, Omega_Psi));
        current_statement__ = 33;
        lp_accum__.add(stan::math::inv_wishart_lpdf<propto__>(Sigma_u, m, V));
      }
    } 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_steady_state_bvar_homoscedastic_inverse_wishart_prior_namespace::write_array";
    // suppress unused var warning
    (void) function__;
    try {
      Eigen::Matrix<double,-1,-1> beta =
        Eigen::Matrix<double,-1,-1>::Constant(beta_1dim__, k,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 1;
      beta = in__.template read<
               Eigen::Matrix<local_scalar_t__,-1,-1>>(beta_1dim__, k);
      Eigen::Matrix<double,-1,-1> Psi =
        Eigen::Matrix<double,-1,-1>::Constant(k, q,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 2;
      Psi = in__.template read<Eigen::Matrix<local_scalar_t__,-1,-1>>(k, q);
      Eigen::Matrix<double,-1,-1> Sigma_u =
        Eigen::Matrix<double,-1,-1>::Constant(k, k,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 3;
      Sigma_u = in__.template read_constrain_cov_matrix<
                  Eigen::Matrix<local_scalar_t__,-1,-1>, jacobian__>(lp__, k);
      out__.write(beta);
      out__.write(Psi);
      out__.write(Sigma_u);
      if (stan::math::logical_negation(
            (stan::math::primitive_value(emit_transformed_parameters__) ||
            stan::math::primitive_value(emit_generated_quantities__)))) {
        return ;
      }
      if (stan::math::logical_negation(emit_generated_quantities__)) {
        return ;
      }
      std::vector<Eigen::Matrix<double,-1,-1>> Pi =
        std::vector<Eigen::Matrix<double,-1,-1>>(p,
          Eigen::Matrix<double,-1,-1>::Constant(k, k,
            std::numeric_limits<double>::quiet_NaN()));
      current_statement__ = 8;
      for (int i = 1; i <= p; ++i) {
        current_statement__ = 6;
        stan::model::assign(Pi,
          stan::math::transpose(
            stan::model::rvalue(beta, "beta",
              stan::model::index_min_max((((i - 1) * k) + 1), (i * k)),
              stan::model::index_omni())), "assigning variable Pi",
          stan::model::index_uni(i));
      }
      Eigen::Matrix<double,-1,-1> y_pred =
        Eigen::Matrix<double,-1,-1>::Constant(H, k,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 25;
      for (int h = 1; h <= H; ++h) {
        current_statement__ = 9;
        stan::math::validate_non_negative_index("u_t", "k", k);
        Eigen::Matrix<double,-1,1> u_t =
          Eigen::Matrix<double,-1,1>::Constant(k,
            std::numeric_limits<double>::quiet_NaN());
        current_statement__ = 10;
        stan::model::assign(u_t,
          stan::math::multi_normal_rng(stan::math::rep_vector(0, k), Sigma_u,
            base_rng__), "assigning variable u_t");
        current_statement__ = 11;
        stan::math::validate_non_negative_index("yhat_t", "k", k);
        Eigen::Matrix<double,-1,1> yhat_t =
          Eigen::Matrix<double,-1,1>::Constant(k,
            std::numeric_limits<double>::quiet_NaN());
        current_statement__ = 12;
        stan::model::assign(yhat_t,
          stan::math::transpose(
            stan::math::multiply(
              stan::model::rvalue(d_pred, "d_pred", stan::model::index_uni(h)),
              stan::math::transpose(Psi))), "assigning variable yhat_t");
        current_statement__ = 17;
        if (stan::math::logical_gt(h, 1)) {
          current_statement__ = 15;
          for (int i = 1; i <= stan::math::min((h - 1), p); ++i) {
            current_statement__ = 13;
            stan::model::assign(yhat_t,
              stan::math::add(stan::model::deep_copy(yhat_t),
                stan::math::to_vector(
                  stan::math::multiply(
                    stan::math::subtract(
                      stan::model::rvalue(y_pred, "y_pred",
                        stan::model::index_uni((h - i))),
                      stan::math::multiply(
                        stan::model::rvalue(d_pred, "d_pred",
                          stan::model::index_uni((h - i))),
                        stan::math::transpose(Psi))),
                    stan::math::transpose(
                      stan::model::rvalue(Pi, "Pi", stan::model::index_uni(i)))))),
              "assigning variable yhat_t");
          }
        }
        current_statement__ = 22;
        if (stan::math::logical_lte(h, p)) {
          current_statement__ = 20;
          for (int i = h; i <= p; ++i) {
            current_statement__ = 18;
            stan::model::assign(yhat_t,
              stan::math::add(stan::model::deep_copy(yhat_t),
                stan::math::to_vector(
                  stan::math::multiply(
                    stan::math::subtract(
                      stan::model::rvalue(Y, "Y",
                        stan::model::index_uni(((N + h) - i))),
                      stan::math::multiply(
                        stan::model::rvalue(D, "D",
                          stan::model::index_uni(((N + h) - i))),
                        stan::math::transpose(Psi))),
                    stan::math::transpose(
                      stan::model::rvalue(Pi, "Pi", stan::model::index_uni(i)))))),
              "assigning variable yhat_t");
          }
        }
        current_statement__ = 23;
        stan::model::assign(y_pred,
          stan::math::transpose(stan::math::add(yhat_t, u_t)),
          "assigning variable y_pred", stan::model::index_uni(h));
      }
      for (int sym1__ = 1; sym1__ <= k; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= k; ++sym2__) {
          for (int sym3__ = 1; sym3__ <= p; ++sym3__) {
            out__.write(stan::model::rvalue(Pi, "Pi",
                          stan::model::index_uni(sym3__),
                          stan::model::index_uni(sym2__),
                          stan::model::index_uni(sym1__)));
          }
        }
      }
      out__.write(y_pred);
    } 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> beta =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(beta_1dim__, k,
          DUMMY_VAR__);
      current_statement__ = 1;
      stan::model::assign(beta,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,-1>>(beta_1dim__, k),
        "assigning variable beta");
      out__.write(beta);
      Eigen::Matrix<local_scalar_t__,-1,-1> Psi =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(k, q, DUMMY_VAR__);
      current_statement__ = 2;
      stan::model::assign(Psi,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,-1>>(k, q),
        "assigning variable Psi");
      out__.write(Psi);
      Eigen::Matrix<local_scalar_t__,-1,-1> Sigma_u =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(k, k, DUMMY_VAR__);
      current_statement__ = 3;
      stan::model::assign(Sigma_u,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,-1>>(k, k),
        "assigning variable Sigma_u");
      out__.write_free_cov_matrix(Sigma_u);
    } 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", "beta", "double",
        std::vector<size_t>{static_cast<size_t>(beta_1dim__),
          static_cast<size_t>(k)});
      current_statement__ = 2;
      context__.validate_dims("parameter initialization", "Psi", "double",
        std::vector<size_t>{static_cast<size_t>(k), static_cast<size_t>(q)});
      current_statement__ = 3;
      context__.validate_dims("parameter initialization", "Sigma_u",
        "double",
        std::vector<size_t>{static_cast<size_t>(k), static_cast<size_t>(k)});
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      Eigen::Matrix<local_scalar_t__,-1,-1> beta =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(beta_1dim__, k,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> beta_flat__;
        current_statement__ = 1;
        beta_flat__ = context__.vals_r("beta");
        current_statement__ = 1;
        pos__ = 1;
        current_statement__ = 1;
        for (int sym1__ = 1; sym1__ <= k; ++sym1__) {
          current_statement__ = 1;
          for (int sym2__ = 1; sym2__ <= beta_1dim__; ++sym2__) {
            current_statement__ = 1;
            stan::model::assign(beta, beta_flat__[(pos__ - 1)],
              "assigning variable beta", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 1;
            pos__ = (pos__ + 1);
          }
        }
      }
      out__.write(beta);
      Eigen::Matrix<local_scalar_t__,-1,-1> Psi =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(k, q, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> Psi_flat__;
        current_statement__ = 2;
        Psi_flat__ = context__.vals_r("Psi");
        current_statement__ = 2;
        pos__ = 1;
        current_statement__ = 2;
        for (int sym1__ = 1; sym1__ <= q; ++sym1__) {
          current_statement__ = 2;
          for (int sym2__ = 1; sym2__ <= k; ++sym2__) {
            current_statement__ = 2;
            stan::model::assign(Psi, Psi_flat__[(pos__ - 1)],
              "assigning variable Psi", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 2;
            pos__ = (pos__ + 1);
          }
        }
      }
      out__.write(Psi);
      Eigen::Matrix<local_scalar_t__,-1,-1> Sigma_u =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(k, k, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> Sigma_u_flat__;
        current_statement__ = 3;
        Sigma_u_flat__ = context__.vals_r("Sigma_u");
        current_statement__ = 3;
        pos__ = 1;
        current_statement__ = 3;
        for (int sym1__ = 1; sym1__ <= k; ++sym1__) {
          current_statement__ = 3;
          for (int sym2__ = 1; sym2__ <= k; ++sym2__) {
            current_statement__ = 3;
            stan::model::assign(Sigma_u, Sigma_u_flat__[(pos__ - 1)],
              "assigning variable Sigma_u", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 3;
            pos__ = (pos__ + 1);
          }
        }
      }
      out__.write_free_cov_matrix(Sigma_u);
    } 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>{"beta", "Psi", "Sigma_u"};
    if (emit_transformed_parameters__) {}
    if (emit_generated_quantities__) {
      std::vector<std::string> temp{"Pi", "y_pred"};
      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>(
                                                                    beta_1dim__),
                                                 static_cast<size_t>(k)},
                std::vector<size_t>{static_cast<size_t>(k),
                  static_cast<size_t>(q)},
                std::vector<size_t>{static_cast<size_t>(k),
                  static_cast<size_t>(k)}};
    if (emit_transformed_parameters__) {}
    if (emit_generated_quantities__) {
      std::vector<std::vector<size_t>>
        temp{std::vector<size_t>{static_cast<size_t>(p),
               static_cast<size_t>(k), static_cast<size_t>(k)},
             std::vector<size_t>{static_cast<size_t>(H),
               static_cast<size_t>(k)}};
      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__ <= k; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= beta_1dim__; ++sym2__) {
        param_names__.emplace_back(std::string() + "beta" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    for (int sym1__ = 1; sym1__ <= q; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= k; ++sym2__) {
        param_names__.emplace_back(std::string() + "Psi" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    for (int sym1__ = 1; sym1__ <= k; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= k; ++sym2__) {
        param_names__.emplace_back(std::string() + "Sigma_u" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    if (emit_transformed_parameters__) {}
    if (emit_generated_quantities__) {
      for (int sym1__ = 1; sym1__ <= k; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= k; ++sym2__) {
          for (int sym3__ = 1; sym3__ <= p; ++sym3__) {
            param_names__.emplace_back(std::string() + "Pi" + '.' +
              std::to_string(sym3__) + '.' + std::to_string(sym2__) + '.' +
              std::to_string(sym1__));
          }
        }
      }
      for (int sym1__ = 1; sym1__ <= k; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= H; ++sym2__) {
          param_names__.emplace_back(std::string() + "y_pred" + '.' +
            std::to_string(sym2__) + '.' + 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__ <= k; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= beta_1dim__; ++sym2__) {
        param_names__.emplace_back(std::string() + "beta" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    for (int sym1__ = 1; sym1__ <= q; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= k; ++sym2__) {
        param_names__.emplace_back(std::string() + "Psi" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    for (int sym1__ = 1; sym1__ <= (k + ((k * (k - 1)) / 2)); ++sym1__) {
      param_names__.emplace_back(std::string() + "Sigma_u" + '.' +
        std::to_string(sym1__));
    }
    if (emit_transformed_parameters__) {}
    if (emit_generated_quantities__) {
      for (int sym1__ = 1; sym1__ <= k; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= k; ++sym2__) {
          for (int sym3__ = 1; sym3__ <= p; ++sym3__) {
            param_names__.emplace_back(std::string() + "Pi" + '.' +
              std::to_string(sym3__) + '.' + std::to_string(sym2__) + '.' +
              std::to_string(sym1__));
          }
        }
      }
      for (int sym1__ = 1; sym1__ <= k; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= H; ++sym2__) {
          param_names__.emplace_back(std::string() + "y_pred" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
    }
  }
  inline std::string get_constrained_sizedtypes() const {
    return std::string("[{\"name\":\"beta\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(beta_1dim__) + ",\"cols\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"Psi\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(k) + ",\"cols\":" + std::to_string(q) + "},\"block\":\"parameters\"},{\"name\":\"Sigma_u\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(k) + ",\"cols\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"Pi\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(p) + ",\"element_type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(k) + ",\"cols\":" + std::to_string(k) + "}},\"block\":\"generated_quantities\"},{\"name\":\"y_pred\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(H) + ",\"cols\":" + std::to_string(k) + "},\"block\":\"generated_quantities\"}]");
  }
  inline std::string get_unconstrained_sizedtypes() const {
    return std::string("[{\"name\":\"beta\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(beta_1dim__) + ",\"cols\":" + std::to_string(k) + "},\"block\":\"parameters\"},{\"name\":\"Psi\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(k) + ",\"cols\":" + std::to_string(q) + "},\"block\":\"parameters\"},{\"name\":\"Sigma_u\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string((k + ((k * (k - 1)) /2))) + "},\"block\":\"parameters\"},{\"name\":\"Pi\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(p) + ",\"element_type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(k) + ",\"cols\":" + std::to_string(k) + "}},\"block\":\"generated_quantities\"},{\"name\":\"y_pred\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(H) + ",\"cols\":" + std::to_string(k) + "},\"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__ = (((beta_1dim__ * k) + (k * q)) + (k * k));
    const size_t num_transformed = emit_transformed_parameters * (0);
    const size_t num_gen_quantities = emit_generated_quantities * ((((p * k)
      * k) + (H * k)));
    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__ = (((beta_1dim__ * k) + (k * q)) + (k * k));
    const size_t num_transformed = emit_transformed_parameters * (0);
    const size_t num_gen_quantities = emit_generated_quantities * ((((p * k)
      * k) + (H * k)));
    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_steady_state_bvar_homoscedastic_inverse_wishart_prior_namespace::model_steady_state_bvar_homoscedastic_inverse_wishart_prior;
#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_steady_state_bvar_homoscedastic_inverse_wishart_prior_namespace::profiles__;
}
#endif
#endif
