Skip to content

Commit

Permalink
Rearrange includes so fwd is included first if STAN_MODEL_FVAR_VAR is…
Browse files Browse the repository at this point in the history
… defined
  • Loading branch information
WardBrian committed Jun 24, 2024
1 parent 5ca84b2 commit 93ad3e0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 37 deletions.
96 changes: 62 additions & 34 deletions src/stan/model/model_base.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef STAN_MODEL_MODEL_BASE_HPP
#define STAN_MODEL_MODEL_BASE_HPP

#include <stan/io/var_context.hpp>
#include <stan/math/rev/core.hpp>
#ifdef STAN_MODEL_FVAR_VAR
#include <stan/math/mix.hpp>
#endif
#include <stan/io/var_context.hpp>
#include <stan/math/rev/core.hpp>
#include <stan/model/prob_grad.hpp>
#include <stan/services/util/create_rng.hpp>
#include <ostream>
Expand Down Expand Up @@ -78,7 +78,8 @@ class model_base : public prob_grad {
*/
virtual void get_param_names(std::vector<std::string>& names,
bool include_tparams = true,
bool include_gqs = true) const = 0;
bool include_gqs = true) const
= 0;
/**
* WARNING: This function bakes in the assumption that the
* parameter values are rectangular. This is already not true
Expand Down Expand Up @@ -107,7 +108,8 @@ class model_base : public prob_grad {
*/
virtual void get_dims(std::vector<std::vector<size_t> >& dimss,
bool include_tparams = true,
bool include_gqs = true) const = 0;
bool include_gqs = true) const
= 0;
/**
* Set the specified sequence to the indexed, scalar, constrained
* parameter names. Each variable is output with a
Expand Down Expand Up @@ -148,7 +150,8 @@ class model_base : public prob_grad {
*/
virtual void constrained_param_names(std::vector<std::string>& param_names,
bool include_tparams = true,
bool include_gqs = true) const = 0;
bool include_gqs = true) const
= 0;

/**
* Set the specified sequence of parameter names to the
Expand Down Expand Up @@ -177,7 +180,8 @@ class model_base : public prob_grad {
*/
virtual void unconstrained_param_names(std::vector<std::string>& param_names,
bool include_tparams = true,
bool include_gqs = true) const = 0;
bool include_gqs = true) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -188,8 +192,8 @@ class model_base : public prob_grad {
* @param[in,out] msgs message stream
* @return log density for specified parameters
*/
virtual double log_prob(Eigen::VectorXd& params_r,
std::ostream* msgs) const = 0;
virtual double log_prob(Eigen::VectorXd& params_r, std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -201,7 +205,8 @@ class model_base : public prob_grad {
* @return log density for specified parameters
*/
virtual math::var log_prob(Eigen::Matrix<math::var, -1, 1>& params_r,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -217,7 +222,8 @@ class model_base : public prob_grad {
* @return log density for specified parameters
*/
virtual double log_prob_jacobian(Eigen::VectorXd& params_r,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -233,7 +239,8 @@ class model_base : public prob_grad {
* @return log density for specified parameters
*/
virtual math::var log_prob_jacobian(Eigen::Matrix<math::var, -1, 1>& params_r,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -250,7 +257,8 @@ class model_base : public prob_grad {
* @return log density for specified parameters
*/
virtual double log_prob_propto(Eigen::VectorXd& params_r,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -262,7 +270,8 @@ class model_base : public prob_grad {
* @return log density for specified parameters
*/
virtual math::var log_prob_propto(Eigen::Matrix<math::var, -1, 1>& params_r,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -283,7 +292,8 @@ class model_base : public prob_grad {
* @return log density for specified parameters
*/
virtual double log_prob_propto_jacobian(Eigen::VectorXd& params_r,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -299,7 +309,8 @@ class model_base : public prob_grad {
* @return log density for specified parameters
*/
virtual math::var log_prob_propto_jacobian(
Eigen::Matrix<math::var, -1, 1>& params_r, std::ostream* msgs) const = 0;
Eigen::Matrix<math::var, -1, 1>& params_r, std::ostream* msgs) const
= 0;

/**
* Convenience template function returning the log density for the
Expand Down Expand Up @@ -347,7 +358,8 @@ class model_base : public prob_grad {
*/
virtual void transform_inits(const io::var_context& context,
Eigen::VectorXd& params_r,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Convert the specified sequence of unconstrained parameters to a
Expand All @@ -370,7 +382,8 @@ class model_base : public prob_grad {
virtual void write_array(stan::rng_t& base_rng, Eigen::VectorXd& params_r,
Eigen::VectorXd& params_constrained_r,
bool include_tparams = true, bool include_gqs = true,
std::ostream* msgs = 0) const = 0;
std::ostream* msgs = 0) const
= 0;

/**
* Convert the specified sequence of constrained parameters to a
Expand All @@ -385,7 +398,8 @@ class model_base : public prob_grad {
*/
virtual void unconstrain_array(const Eigen::VectorXd& params_r_constrained,
Eigen::VectorXd& params_r,
std::ostream* msgs = nullptr) const = 0;
std::ostream* msgs = nullptr) const
= 0;

// TODO(carpenter): cut redundant std::vector versions from here ===

Expand All @@ -402,8 +416,8 @@ class model_base : public prob_grad {
* @return log density for specified parameters
*/
virtual double log_prob(std::vector<double>& params_r,
std::vector<int>& params_i,
std::ostream* msgs) const = 0;
std::vector<int>& params_i, std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -419,7 +433,8 @@ class model_base : public prob_grad {
*/
virtual math::var log_prob(std::vector<math::var>& params_r,
std::vector<int>& params_i,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -439,7 +454,8 @@ class model_base : public prob_grad {
*/
virtual double log_prob_jacobian(std::vector<double>& params_r,
std::vector<int>& params_i,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -459,7 +475,8 @@ class model_base : public prob_grad {
*/
virtual math::var log_prob_jacobian(std::vector<math::var>& params_r,
std::vector<int>& params_i,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -480,7 +497,8 @@ class model_base : public prob_grad {
*/
virtual double log_prob_propto(std::vector<double>& params_r,
std::vector<int>& params_i,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -496,7 +514,8 @@ class model_base : public prob_grad {
*/
virtual math::var log_prob_propto(std::vector<math::var>& params_r,
std::vector<int>& params_i,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -521,7 +540,8 @@ class model_base : public prob_grad {
*/
virtual double log_prob_propto_jacobian(std::vector<double>& params_r,
std::vector<int>& params_i,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -541,7 +561,8 @@ class model_base : public prob_grad {
*/
virtual math::var log_prob_propto_jacobian(std::vector<math::var>& params_r,
std::vector<int>& params_i,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Convenience template function returning the log density for the
Expand Down Expand Up @@ -596,7 +617,8 @@ class model_base : public prob_grad {
virtual void transform_inits(const io::var_context& context,
std::vector<int>& params_i,
std::vector<double>& params_r,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Convert the specified sequence of unconstrained parameters to a
Expand All @@ -621,7 +643,8 @@ class model_base : public prob_grad {
std::vector<int>& params_i,
std::vector<double>& params_r_constrained,
bool include_tparams = true, bool include_gqs = true,
std::ostream* msgs = 0) const = 0;
std::ostream* msgs = 0) const
= 0;

/**
* Convert the specified sequence of constrained parameters to a
Expand All @@ -636,7 +659,8 @@ class model_base : public prob_grad {
*/
virtual void unconstrain_array(
const std::vector<double>& params_r_constrained,
std::vector<double>& params_r, std::ostream* msgs = nullptr) const = 0;
std::vector<double>& params_r, std::ostream* msgs = nullptr) const
= 0;

#ifdef STAN_MODEL_FVAR_VAR

Expand All @@ -651,7 +675,8 @@ class model_base : public prob_grad {
*/
virtual math::fvar<math::var> log_prob(
Eigen::Matrix<math::fvar<math::var>, -1, 1>& params_r,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -668,7 +693,8 @@ class model_base : public prob_grad {
*/
virtual math::fvar<math::var> log_prob_jacobian(
Eigen::Matrix<math::fvar<math::var>, -1, 1>& params_r,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -681,7 +707,8 @@ class model_base : public prob_grad {
*/
virtual math::fvar<math::var> log_prob_propto(
Eigen::Matrix<math::fvar<math::var>, -1, 1>& params_r,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;

/**
* Return the log density for the specified unconstrained
Expand All @@ -698,7 +725,8 @@ class model_base : public prob_grad {
*/
virtual math::fvar<math::var> log_prob_propto_jacobian(
Eigen::Matrix<math::fvar<math::var>, -1, 1>& params_r,
std::ostream* msgs) const = 0;
std::ostream* msgs) const
= 0;
#endif
};

Expand Down
2 changes: 1 addition & 1 deletion src/stan/model/model_base_crtp.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef STAN_MODEL_MODEL_BASE_CRTP_HPP
#define STAN_MODEL_MODEL_BASE_CRTP_HPP

#include <stan/model/model_base.hpp>
#ifdef STAN_MODEL_FVAR_VAR
#include <stan/math/mix.hpp>
#endif
#include <stan/model/model_base.hpp>
#include <iostream>
#include <utility>
#include <vector>
Expand Down
4 changes: 2 additions & 2 deletions src/stan/model/model_header.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#ifndef STAN_MODEL_MODEL_HEADER_HPP
#define STAN_MODEL_MODEL_HEADER_HPP

#include <stan/model/model_base.hpp>
#include <stan/model/model_base_crtp.hpp>
#include <stan/math.hpp>

#include <stan/io/deserializer.hpp>
#include <stan/io/serializer.hpp>

#include <stan/model/rethrow_located.hpp>
#include <stan/model/model_base.hpp>
#include <stan/model/model_base_crtp.hpp>
#include <stan/model/prob_grad.hpp>
#include <stan/model/indexing.hpp>
#include <stan/services/util/create_rng.hpp>
Expand Down

0 comments on commit 93ad3e0

Please sign in to comment.