#ifndef MODELS_HPP
#define MODELS_HPP
#define STAN__SERVICES__COMMAND_HPP
#include <rstan/rstaninc.hpp>
#ifndef USE_STANC3
#define USE_STANC3
#endif
// Code generated by stanc v2.32.2
#include <stan/model/model_header.hpp>
namespace model3287395d08f6__namespace {
using stan::model::model_base_crtp;
using namespace stan::math;
stan::math::profile_map profiles__;
static constexpr std::array<const char*, 40> locations_array__ =
  {" (found before start of program)",
  " (in 'anon_model', line 20, column 2 to column 17)",
  " (in 'anon_model', line 21, column 2 to column 28)",
  " (in 'anon_model', line 22, column 2 to column 29)",
  " (in 'anon_model', line 25, column 2 to column 17)",
  " (in 'anon_model', line 26, column 2 to column 20)",
  " (in 'anon_model', line 28, column 2 to column 18)",
  " (in 'anon_model', line 52, column 2 to column 31)",
  " (in 'anon_model', line 29, column 2 to column 31)",
  " (in 'anon_model', line 30, column 2 to column 42)",
  " (in 'anon_model', line 31, column 2 to line 32, column 35)",
  " (in 'anon_model', line 38, column 11 to column 12)",
  " (in 'anon_model', line 38, column 4 to column 38)",
  " (in 'anon_model', line 39, column 4 to column 20)",
  " (in 'anon_model', line 42, column 6 to column 40)",
  " (in 'anon_model', line 40, column 19 to line 43, column 5)",
  " (in 'anon_model', line 40, column 4 to line 43, column 5)",
  " (in 'anon_model', line 44, column 4 to column 38)",
  " (in 'anon_model', line 36, column 19 to line 45, column 3)",
  " (in 'anon_model', line 36, column 2 to line 45, column 3)",
  " (in 'anon_model', line 47, column 2 to column 19)",
  " (in 'anon_model', line 48, column 2 to column 36)",
  " (in 'anon_model', line 5, column 2 to column 17)",
  " (in 'anon_model', line 6, column 9 to column 10)",
  " (in 'anon_model', line 6, column 2 to column 14)",
  " (in 'anon_model', line 7, column 18 to column 19)",
  " (in 'anon_model', line 7, column 2 to column 24)",
  " (in 'anon_model', line 9, column 2 to column 19)",
  " (in 'anon_model', line 10, column 2 to column 19)",
  " (in 'anon_model', line 11, column 8 to column 9)",
  " (in 'anon_model', line 11, column 2 to column 28)",
  " (in 'anon_model', line 13, column 9 to column 10)",
  " (in 'anon_model', line 13, column 2 to column 18)",
  " (in 'anon_model', line 14, column 2 to column 17)",
  " (in 'anon_model', line 17, column 18 to column 19)",
  " (in 'anon_model', line 17, column 2 to column 38)",
  " (in 'anon_model', line 21, column 18 to column 21)",
  " (in 'anon_model', line 22, column 8 to column 11)",
  " (in 'anon_model', line 22, column 20 to column 23)",
  " (in 'anon_model', line 26, column 9 to column 12)"};
class model3287395d08f6_ final : public model_base_crtp<model3287395d08f6_> {
private:
  int N;
  Eigen::Matrix<double,-1,1> Y_data__;
  Eigen::Matrix<double,-1,1> se_data__;
  int N_1;
  int M_1;
  std::vector<int> J_1;
  Eigen::Matrix<double,-1,1> Z_1_1_data__;
  int prior_only;
  Eigen::Matrix<double,-1,1> se2_data__;
  Eigen::Map<Eigen::Matrix<double,-1,1>> Y{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> se{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> Z_1_1{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> se2{nullptr, 0};
public:
  ~model3287395d08f6_() {}
  model3287395d08f6_(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__ =
      "model3287395d08f6__namespace::model3287395d08f6_";
    // 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__ = 22;
      context__.validate_dims("data initialization", "N", "int",
        std::vector<size_t>{});
      N = std::numeric_limits<int>::min();
      current_statement__ = 22;
      N = context__.vals_i("N")[(1 - 1)];
      current_statement__ = 22;
      stan::math::check_greater_or_equal(function__, "N", N, 1);
      current_statement__ = 23;
      stan::math::validate_non_negative_index("Y", "N", N);
      current_statement__ = 24;
      context__.validate_dims("data initialization", "Y", "double",
        std::vector<size_t>{static_cast<size_t>(N)});
      Y_data__ = Eigen::Matrix<double,-1,1>::Constant(N,
                   std::numeric_limits<double>::quiet_NaN());
      new (&Y) Eigen::Map<Eigen::Matrix<double,-1,1>>(Y_data__.data(), N);
      {
        std::vector<local_scalar_t__> Y_flat__;
        current_statement__ = 24;
        Y_flat__ = context__.vals_r("Y");
        current_statement__ = 24;
        pos__ = 1;
        current_statement__ = 24;
        for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
          current_statement__ = 24;
          stan::model::assign(Y, Y_flat__[(pos__ - 1)],
            "assigning variable Y", stan::model::index_uni(sym1__));
          current_statement__ = 24;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 25;
      stan::math::validate_non_negative_index("se", "N", N);
      current_statement__ = 26;
      context__.validate_dims("data initialization", "se", "double",
        std::vector<size_t>{static_cast<size_t>(N)});
      se_data__ = Eigen::Matrix<double,-1,1>::Constant(N,
                    std::numeric_limits<double>::quiet_NaN());
      new (&se) Eigen::Map<Eigen::Matrix<double,-1,1>>(se_data__.data(), N);
      {
        std::vector<local_scalar_t__> se_flat__;
        current_statement__ = 26;
        se_flat__ = context__.vals_r("se");
        current_statement__ = 26;
        pos__ = 1;
        current_statement__ = 26;
        for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
          current_statement__ = 26;
          stan::model::assign(se, se_flat__[(pos__ - 1)],
            "assigning variable se", stan::model::index_uni(sym1__));
          current_statement__ = 26;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 26;
      stan::math::check_greater_or_equal(function__, "se", se, 0);
      current_statement__ = 27;
      context__.validate_dims("data initialization", "N_1", "int",
        std::vector<size_t>{});
      N_1 = std::numeric_limits<int>::min();
      current_statement__ = 27;
      N_1 = context__.vals_i("N_1")[(1 - 1)];
      current_statement__ = 27;
      stan::math::check_greater_or_equal(function__, "N_1", N_1, 1);
      current_statement__ = 28;
      context__.validate_dims("data initialization", "M_1", "int",
        std::vector<size_t>{});
      M_1 = std::numeric_limits<int>::min();
      current_statement__ = 28;
      M_1 = context__.vals_i("M_1")[(1 - 1)];
      current_statement__ = 28;
      stan::math::check_greater_or_equal(function__, "M_1", M_1, 1);
      current_statement__ = 29;
      stan::math::validate_non_negative_index("J_1", "N", N);
      current_statement__ = 30;
      context__.validate_dims("data initialization", "J_1", "int",
        std::vector<size_t>{static_cast<size_t>(N)});
      J_1 = std::vector<int>(N, std::numeric_limits<int>::min());
      current_statement__ = 30;
      J_1 = context__.vals_i("J_1");
      current_statement__ = 30;
      stan::math::check_greater_or_equal(function__, "J_1", J_1, 1);
      current_statement__ = 31;
      stan::math::validate_non_negative_index("Z_1_1", "N", N);
      current_statement__ = 32;
      context__.validate_dims("data initialization", "Z_1_1", "double",
        std::vector<size_t>{static_cast<size_t>(N)});
      Z_1_1_data__ = Eigen::Matrix<double,-1,1>::Constant(N,
                       std::numeric_limits<double>::quiet_NaN());
      new (&Z_1_1)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(Z_1_1_data__.data(), N);
      {
        std::vector<local_scalar_t__> Z_1_1_flat__;
        current_statement__ = 32;
        Z_1_1_flat__ = context__.vals_r("Z_1_1");
        current_statement__ = 32;
        pos__ = 1;
        current_statement__ = 32;
        for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
          current_statement__ = 32;
          stan::model::assign(Z_1_1, Z_1_1_flat__[(pos__ - 1)],
            "assigning variable Z_1_1", stan::model::index_uni(sym1__));
          current_statement__ = 32;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 33;
      context__.validate_dims("data initialization", "prior_only", "int",
        std::vector<size_t>{});
      prior_only = std::numeric_limits<int>::min();
      current_statement__ = 33;
      prior_only = context__.vals_i("prior_only")[(1 - 1)];
      current_statement__ = 34;
      stan::math::validate_non_negative_index("se2", "N", N);
      current_statement__ = 35;
      se2_data__ = Eigen::Matrix<double,-1,1>::Constant(N,
                     std::numeric_limits<double>::quiet_NaN());
      new (&se2) Eigen::Map<Eigen::Matrix<double,-1,1>>(se2_data__.data(), N);
      current_statement__ = 35;
      stan::model::assign(se2, stan::math::square(se),
        "assigning variable se2");
      current_statement__ = 35;
      stan::math::check_greater_or_equal(function__, "se2", se2, 0);
      current_statement__ = 36;
      stan::math::validate_non_negative_index("sd_1", "M_1", M_1);
      current_statement__ = 37;
      stan::math::validate_non_negative_index("z_1", "M_1", M_1);
      current_statement__ = 38;
      stan::math::validate_non_negative_index("z_1", "N_1", N_1);
      current_statement__ = 39;
      stan::math::validate_non_negative_index("r_1_1", "N_1", N_1);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
    num_params_r__ = 1 + M_1 + (M_1 * N_1);
  }
  inline std::string model_name() const final {
    return "model3287395d08f6_";
  }
  inline std::vector<std::string> model_compile_info() const noexcept {
    return std::vector<std::string>{"stanc_version = stanc3 v2.32.2",
             "stancflags = --"};
  }
  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__ =
      "model3287395d08f6__namespace::log_prob";
    // suppress unused var warning
    (void) function__;
    try {
      local_scalar_t__ Intercept = DUMMY_VAR__;
      current_statement__ = 1;
      Intercept = in__.template read<local_scalar_t__>();
      Eigen::Matrix<local_scalar_t__,-1,1> sd_1 =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(M_1, DUMMY_VAR__);
      current_statement__ = 2;
      sd_1 = in__.template read_constrain_lb<
               Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(0, lp__,
               M_1);
      std::vector<Eigen::Matrix<local_scalar_t__,-1,1>> z_1 =
        std::vector<Eigen::Matrix<local_scalar_t__,-1,1>>(M_1,
          Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_1, DUMMY_VAR__));
      current_statement__ = 3;
      z_1 = in__.template read<
              std::vector<Eigen::Matrix<local_scalar_t__,-1,1>>>(M_1, N_1);
      local_scalar_t__ sigma = DUMMY_VAR__;
      current_statement__ = 4;
      sigma = 0;
      Eigen::Matrix<local_scalar_t__,-1,1> r_1_1 =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_1, DUMMY_VAR__);
      local_scalar_t__ lprior = DUMMY_VAR__;
      current_statement__ = 6;
      lprior = 0;
      current_statement__ = 8;
      stan::model::assign(r_1_1,
        stan::math::multiply(
          stan::model::rvalue(sd_1, "sd_1", stan::model::index_uni(1)),
          stan::model::rvalue(z_1, "z_1", stan::model::index_uni(1))),
        "assigning variable r_1_1");
      current_statement__ = 9;
      lprior = (lprior + stan::math::normal_lpdf<false>(Intercept, 0, 1));
      current_statement__ = 10;
      lprior = (lprior + (stan::math::normal_lpdf<false>(sd_1, 0, 0.5) - (1 *
        stan::math::normal_lccdf(0, 0, 0.5))));
      {
        current_statement__ = 19;
        if (stan::math::logical_negation(prior_only)) {
          current_statement__ = 11;
          stan::math::validate_non_negative_index("mu", "N", N);
          Eigen::Matrix<local_scalar_t__,-1,1> mu =
            Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N, DUMMY_VAR__);
          current_statement__ = 12;
          stan::model::assign(mu, stan::math::rep_vector(0.0, N),
            "assigning variable mu");
          current_statement__ = 13;
          stan::model::assign(mu,
            stan::math::add(stan::model::deep_copy(mu), Intercept),
            "assigning variable mu");
          current_statement__ = 16;
          for (int n = 1; n <= N; ++n) {
            current_statement__ = 14;
            stan::model::assign(mu,
              (stan::model::rvalue(mu, "mu", stan::model::index_uni(n)) +
              (stan::model::rvalue(r_1_1, "r_1_1",
                 stan::model::index_uni(
                   stan::model::rvalue(J_1, "J_1", stan::model::index_uni(n))))
              *
              stan::model::rvalue(Z_1_1, "Z_1_1", stan::model::index_uni(n)))),
              "assigning variable mu", stan::model::index_uni(n));
          }
          current_statement__ = 17;
          lp_accum__.add(stan::math::normal_lpdf<false>(Y, mu, se));
        }
        current_statement__ = 20;
        lp_accum__.add(lprior);
        current_statement__ = 21;
        lp_accum__.add(stan::math::std_normal_lpdf<false>(
                         stan::model::rvalue(z_1, "z_1",
                           stan::model::index_uni(1))));
      }
    } 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__ =
      "model3287395d08f6__namespace::write_array";
    // suppress unused var warning
    (void) function__;
    try {
      double Intercept = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 1;
      Intercept = in__.template read<local_scalar_t__>();
      Eigen::Matrix<double,-1,1> sd_1 =
        Eigen::Matrix<double,-1,1>::Constant(M_1,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 2;
      sd_1 = in__.template read_constrain_lb<
               Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(0, lp__,
               M_1);
      std::vector<Eigen::Matrix<double,-1,1>> z_1 =
        std::vector<Eigen::Matrix<double,-1,1>>(M_1,
          Eigen::Matrix<double,-1,1>::Constant(N_1,
            std::numeric_limits<double>::quiet_NaN()));
      current_statement__ = 3;
      z_1 = in__.template read<
              std::vector<Eigen::Matrix<local_scalar_t__,-1,1>>>(M_1, N_1);
      double sigma = std::numeric_limits<double>::quiet_NaN();
      Eigen::Matrix<double,-1,1> r_1_1 =
        Eigen::Matrix<double,-1,1>::Constant(N_1,
          std::numeric_limits<double>::quiet_NaN());
      double lprior = std::numeric_limits<double>::quiet_NaN();
      out__.write(Intercept);
      out__.write(sd_1);
      for (int sym1__ = 1; sym1__ <= N_1; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= M_1; ++sym2__) {
          out__.write(z_1[(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__ = 4;
      sigma = 0;
      current_statement__ = 6;
      lprior = 0;
      current_statement__ = 8;
      stan::model::assign(r_1_1,
        stan::math::multiply(
          stan::model::rvalue(sd_1, "sd_1", stan::model::index_uni(1)),
          stan::model::rvalue(z_1, "z_1", stan::model::index_uni(1))),
        "assigning variable r_1_1");
      current_statement__ = 9;
      lprior = (lprior + stan::math::normal_lpdf<false>(Intercept, 0, 1));
      current_statement__ = 10;
      lprior = (lprior + (stan::math::normal_lpdf<false>(sd_1, 0, 0.5) - (1 *
        stan::math::normal_lccdf(0, 0, 0.5))));
      if (emit_transformed_parameters__) {
        out__.write(sigma);
        out__.write(r_1_1);
        out__.write(lprior);
      }
      if (stan::math::logical_negation(emit_generated_quantities__)) {
        return ;
      }
      double b_Intercept = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 7;
      b_Intercept = Intercept;
      out__.write(b_Intercept);
    } 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;
      local_scalar_t__ Intercept = DUMMY_VAR__;
      current_statement__ = 1;
      Intercept = in__.read<local_scalar_t__>();
      out__.write(Intercept);
      Eigen::Matrix<local_scalar_t__,-1,1> sd_1 =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(M_1, DUMMY_VAR__);
      current_statement__ = 2;
      stan::model::assign(sd_1,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(M_1),
        "assigning variable sd_1");
      out__.write_free_lb(0, sd_1);
      std::vector<Eigen::Matrix<local_scalar_t__,-1,1>> z_1 =
        std::vector<Eigen::Matrix<local_scalar_t__,-1,1>>(M_1,
          Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_1, DUMMY_VAR__));
      current_statement__ = 3;
      for (int sym1__ = 1; sym1__ <= N_1; ++sym1__) {
        current_statement__ = 3;
        for (int sym2__ = 1; sym2__ <= M_1; ++sym2__) {
          current_statement__ = 3;
          stan::model::assign(z_1, in__.read<local_scalar_t__>(),
            "assigning variable z_1", stan::model::index_uni(sym2__),
            stan::model::index_uni(sym1__));
        }
      }
      out__.write(z_1);
    } 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", "Intercept",
        "double", std::vector<size_t>{});
      current_statement__ = 2;
      context__.validate_dims("parameter initialization", "sd_1", "double",
        std::vector<size_t>{static_cast<size_t>(M_1)});
      current_statement__ = 3;
      context__.validate_dims("parameter initialization", "z_1", "double",
        std::vector<size_t>{static_cast<size_t>(M_1),
          static_cast<size_t>(N_1)});
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      local_scalar_t__ Intercept = DUMMY_VAR__;
      current_statement__ = 1;
      Intercept = context__.vals_r("Intercept")[(1 - 1)];
      out__.write(Intercept);
      Eigen::Matrix<local_scalar_t__,-1,1> sd_1 =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(M_1, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> sd_1_flat__;
        current_statement__ = 2;
        sd_1_flat__ = context__.vals_r("sd_1");
        current_statement__ = 2;
        pos__ = 1;
        current_statement__ = 2;
        for (int sym1__ = 1; sym1__ <= M_1; ++sym1__) {
          current_statement__ = 2;
          stan::model::assign(sd_1, sd_1_flat__[(pos__ - 1)],
            "assigning variable sd_1", stan::model::index_uni(sym1__));
          current_statement__ = 2;
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_lb(0, sd_1);
      std::vector<Eigen::Matrix<local_scalar_t__,-1,1>> z_1 =
        std::vector<Eigen::Matrix<local_scalar_t__,-1,1>>(M_1,
          Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_1, DUMMY_VAR__));
      {
        std::vector<local_scalar_t__> z_1_flat__;
        current_statement__ = 3;
        z_1_flat__ = context__.vals_r("z_1");
        current_statement__ = 3;
        pos__ = 1;
        current_statement__ = 3;
        for (int sym1__ = 1; sym1__ <= N_1; ++sym1__) {
          current_statement__ = 3;
          for (int sym2__ = 1; sym2__ <= M_1; ++sym2__) {
            current_statement__ = 3;
            stan::model::assign(z_1, z_1_flat__[(pos__ - 1)],
              "assigning variable z_1", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 3;
            pos__ = (pos__ + 1);
          }
        }
      }
      out__.write(z_1);
    } 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>{"Intercept", "sd_1", "z_1"};
    if (emit_transformed_parameters__) {
      std::vector<std::string> temp{"sigma", "r_1_1", "lprior"};
      names__.reserve(names__.size() + temp.size());
      names__.insert(names__.end(), temp.begin(), temp.end());
    }
    if (emit_generated_quantities__) {
      std::vector<std::string> temp{"b_Intercept"};
      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>{},
                std::vector<size_t>{static_cast<size_t>(M_1)},
                std::vector<size_t>{static_cast<size_t>(M_1),
                  static_cast<size_t>(N_1)}};
    if (emit_transformed_parameters__) {
      std::vector<std::vector<size_t>>
        temp{std::vector<size_t>{},
             std::vector<size_t>{static_cast<size_t>(N_1)},
             std::vector<size_t>{}};
      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>{}};
      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 {
    param_names__.emplace_back(std::string() + "Intercept");
    for (int sym1__ = 1; sym1__ <= M_1; ++sym1__) {
      param_names__.emplace_back(std::string() + "sd_1" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= N_1; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= M_1; ++sym2__) {
        param_names__.emplace_back(std::string() + "z_1" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    if (emit_transformed_parameters__) {
      param_names__.emplace_back(std::string() + "sigma");
      for (int sym1__ = 1; sym1__ <= N_1; ++sym1__) {
        param_names__.emplace_back(std::string() + "r_1_1" + '.' +
          std::to_string(sym1__));
      }
      param_names__.emplace_back(std::string() + "lprior");
    }
    if (emit_generated_quantities__) {
      param_names__.emplace_back(std::string() + "b_Intercept");
    }
  }
  inline void
  unconstrained_param_names(std::vector<std::string>& param_names__, bool
                            emit_transformed_parameters__ = true, bool
                            emit_generated_quantities__ = true) const final {
    param_names__.emplace_back(std::string() + "Intercept");
    for (int sym1__ = 1; sym1__ <= M_1; ++sym1__) {
      param_names__.emplace_back(std::string() + "sd_1" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= N_1; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= M_1; ++sym2__) {
        param_names__.emplace_back(std::string() + "z_1" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    if (emit_transformed_parameters__) {
      param_names__.emplace_back(std::string() + "sigma");
      for (int sym1__ = 1; sym1__ <= N_1; ++sym1__) {
        param_names__.emplace_back(std::string() + "r_1_1" + '.' +
          std::to_string(sym1__));
      }
      param_names__.emplace_back(std::string() + "lprior");
    }
    if (emit_generated_quantities__) {
      param_names__.emplace_back(std::string() + "b_Intercept");
    }
  }
  inline std::string get_constrained_sizedtypes() const {
    return std::string("[{\"name\":\"Intercept\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"sd_1\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(M_1) + "},\"block\":\"parameters\"},{\"name\":\"z_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(M_1) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_1) + "}},\"block\":\"parameters\"},{\"name\":\"sigma\",\"type\":{\"name\":\"real\"},\"block\":\"transformed_parameters\"},{\"name\":\"r_1_1\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_1) + "},\"block\":\"transformed_parameters\"},{\"name\":\"lprior\",\"type\":{\"name\":\"real\"},\"block\":\"transformed_parameters\"},{\"name\":\"b_Intercept\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]");
  }
  inline std::string get_unconstrained_sizedtypes() const {
    return std::string("[{\"name\":\"Intercept\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"sd_1\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(M_1) + "},\"block\":\"parameters\"},{\"name\":\"z_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(M_1) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_1) + "}},\"block\":\"parameters\"},{\"name\":\"sigma\",\"type\":{\"name\":\"real\"},\"block\":\"transformed_parameters\"},{\"name\":\"r_1_1\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_1) + "},\"block\":\"transformed_parameters\"},{\"name\":\"lprior\",\"type\":{\"name\":\"real\"},\"block\":\"transformed_parameters\"},{\"name\":\"b_Intercept\",\"type\":{\"name\":\"real\"},\"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__ = ((1 + M_1) + (M_1 * N_1));
    const size_t num_transformed = emit_transformed_parameters * (((1 + N_1)
      + 1));
    const size_t num_gen_quantities = emit_generated_quantities * (1);
    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__ = ((1 + M_1) + (M_1 * N_1));
    const size_t num_transformed = emit_transformed_parameters * (((1 + N_1)
      + 1));
    const size_t num_gen_quantities = emit_generated_quantities * (1);
    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 = model3287395d08f6__namespace::model3287395d08f6_;
#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 model3287395d08f6__namespace::profiles__;
}
#endif
#endif