From 5ca84b2a6fa38a82902a2204cb10c0745f238509 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Mon, 24 Jun 2024 12:06:00 -0400 Subject: [PATCH 1/3] Add failing test --- src/test/test-models/good/model/accumulate.stan | 9 +++++++++ src/test/unit/model/compile_test.cpp | 2 ++ 2 files changed, 11 insertions(+) create mode 100644 src/test/test-models/good/model/accumulate.stan create mode 100644 src/test/unit/model/compile_test.cpp diff --git a/src/test/test-models/good/model/accumulate.stan b/src/test/test-models/good/model/accumulate.stan new file mode 100644 index 0000000000..4246875145 --- /dev/null +++ b/src/test/test-models/good/model/accumulate.stan @@ -0,0 +1,9 @@ +data { + int N; +} +parameters { + vector[N] y; +} +model { + target += y; +} diff --git a/src/test/unit/model/compile_test.cpp b/src/test/unit/model/compile_test.cpp new file mode 100644 index 0000000000..abd9f383df --- /dev/null +++ b/src/test/unit/model/compile_test.cpp @@ -0,0 +1,2 @@ +// test model which previously failed with -DSTAN_MODEL_FVAR_VAR +#include From 93ad3e0f38d55b048f08b321d860dd19bb237900 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Mon, 24 Jun 2024 12:06:50 -0400 Subject: [PATCH 2/3] Rearrange includes so fwd is included first if STAN_MODEL_FVAR_VAR is defined --- src/stan/model/model_base.hpp | 96 +++++++++++++++++++----------- src/stan/model/model_base_crtp.hpp | 2 +- src/stan/model/model_header.hpp | 4 +- 3 files changed, 65 insertions(+), 37 deletions(-) diff --git a/src/stan/model/model_base.hpp b/src/stan/model/model_base.hpp index 1f6de972f9..a8196d93d7 100644 --- a/src/stan/model/model_base.hpp +++ b/src/stan/model/model_base.hpp @@ -1,11 +1,11 @@ #ifndef STAN_MODEL_MODEL_BASE_HPP #define STAN_MODEL_MODEL_BASE_HPP -#include -#include #ifdef STAN_MODEL_FVAR_VAR #include #endif +#include +#include #include #include #include @@ -78,7 +78,8 @@ class model_base : public prob_grad { */ virtual void get_param_names(std::vector& 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 @@ -107,7 +108,8 @@ class model_base : public prob_grad { */ virtual void get_dims(std::vector >& 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 @@ -148,7 +150,8 @@ class model_base : public prob_grad { */ virtual void constrained_param_names(std::vector& 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 @@ -177,7 +180,8 @@ class model_base : public prob_grad { */ virtual void unconstrained_param_names(std::vector& 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 @@ -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 @@ -201,7 +205,8 @@ class model_base : public prob_grad { * @return log density for specified parameters */ virtual math::var log_prob(Eigen::Matrix& params_r, - std::ostream* msgs) const = 0; + std::ostream* msgs) const + = 0; /** * Return the log density for the specified unconstrained @@ -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 @@ -233,7 +239,8 @@ class model_base : public prob_grad { * @return log density for specified parameters */ virtual math::var log_prob_jacobian(Eigen::Matrix& params_r, - std::ostream* msgs) const = 0; + std::ostream* msgs) const + = 0; /** * Return the log density for the specified unconstrained @@ -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 @@ -262,7 +270,8 @@ class model_base : public prob_grad { * @return log density for specified parameters */ virtual math::var log_prob_propto(Eigen::Matrix& params_r, - std::ostream* msgs) const = 0; + std::ostream* msgs) const + = 0; /** * Return the log density for the specified unconstrained @@ -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 @@ -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& params_r, std::ostream* msgs) const = 0; + Eigen::Matrix& params_r, std::ostream* msgs) const + = 0; /** * Convenience template function returning the log density for the @@ -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 @@ -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 @@ -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 === @@ -402,8 +416,8 @@ class model_base : public prob_grad { * @return log density for specified parameters */ virtual double log_prob(std::vector& params_r, - std::vector& params_i, - std::ostream* msgs) const = 0; + std::vector& params_i, std::ostream* msgs) const + = 0; /** * Return the log density for the specified unconstrained @@ -419,7 +433,8 @@ class model_base : public prob_grad { */ virtual math::var log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* msgs) const = 0; + std::ostream* msgs) const + = 0; /** * Return the log density for the specified unconstrained @@ -439,7 +454,8 @@ class model_base : public prob_grad { */ virtual double log_prob_jacobian(std::vector& params_r, std::vector& params_i, - std::ostream* msgs) const = 0; + std::ostream* msgs) const + = 0; /** * Return the log density for the specified unconstrained @@ -459,7 +475,8 @@ class model_base : public prob_grad { */ virtual math::var log_prob_jacobian(std::vector& params_r, std::vector& params_i, - std::ostream* msgs) const = 0; + std::ostream* msgs) const + = 0; /** * Return the log density for the specified unconstrained @@ -480,7 +497,8 @@ class model_base : public prob_grad { */ virtual double log_prob_propto(std::vector& params_r, std::vector& params_i, - std::ostream* msgs) const = 0; + std::ostream* msgs) const + = 0; /** * Return the log density for the specified unconstrained @@ -496,7 +514,8 @@ class model_base : public prob_grad { */ virtual math::var log_prob_propto(std::vector& params_r, std::vector& params_i, - std::ostream* msgs) const = 0; + std::ostream* msgs) const + = 0; /** * Return the log density for the specified unconstrained @@ -521,7 +540,8 @@ class model_base : public prob_grad { */ virtual double log_prob_propto_jacobian(std::vector& params_r, std::vector& params_i, - std::ostream* msgs) const = 0; + std::ostream* msgs) const + = 0; /** * Return the log density for the specified unconstrained @@ -541,7 +561,8 @@ class model_base : public prob_grad { */ virtual math::var log_prob_propto_jacobian(std::vector& params_r, std::vector& params_i, - std::ostream* msgs) const = 0; + std::ostream* msgs) const + = 0; /** * Convenience template function returning the log density for the @@ -596,7 +617,8 @@ class model_base : public prob_grad { virtual void transform_inits(const io::var_context& context, std::vector& params_i, std::vector& params_r, - std::ostream* msgs) const = 0; + std::ostream* msgs) const + = 0; /** * Convert the specified sequence of unconstrained parameters to a @@ -621,7 +643,8 @@ class model_base : public prob_grad { std::vector& params_i, std::vector& 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 @@ -636,7 +659,8 @@ class model_base : public prob_grad { */ virtual void unconstrain_array( const std::vector& params_r_constrained, - std::vector& params_r, std::ostream* msgs = nullptr) const = 0; + std::vector& params_r, std::ostream* msgs = nullptr) const + = 0; #ifdef STAN_MODEL_FVAR_VAR @@ -651,7 +675,8 @@ class model_base : public prob_grad { */ virtual math::fvar log_prob( Eigen::Matrix, -1, 1>& params_r, - std::ostream* msgs) const = 0; + std::ostream* msgs) const + = 0; /** * Return the log density for the specified unconstrained @@ -668,7 +693,8 @@ class model_base : public prob_grad { */ virtual math::fvar log_prob_jacobian( Eigen::Matrix, -1, 1>& params_r, - std::ostream* msgs) const = 0; + std::ostream* msgs) const + = 0; /** * Return the log density for the specified unconstrained @@ -681,7 +707,8 @@ class model_base : public prob_grad { */ virtual math::fvar log_prob_propto( Eigen::Matrix, -1, 1>& params_r, - std::ostream* msgs) const = 0; + std::ostream* msgs) const + = 0; /** * Return the log density for the specified unconstrained @@ -698,7 +725,8 @@ class model_base : public prob_grad { */ virtual math::fvar log_prob_propto_jacobian( Eigen::Matrix, -1, 1>& params_r, - std::ostream* msgs) const = 0; + std::ostream* msgs) const + = 0; #endif }; diff --git a/src/stan/model/model_base_crtp.hpp b/src/stan/model/model_base_crtp.hpp index 1868b3e056..cfb54a91ad 100644 --- a/src/stan/model/model_base_crtp.hpp +++ b/src/stan/model/model_base_crtp.hpp @@ -1,10 +1,10 @@ #ifndef STAN_MODEL_MODEL_BASE_CRTP_HPP #define STAN_MODEL_MODEL_BASE_CRTP_HPP -#include #ifdef STAN_MODEL_FVAR_VAR #include #endif +#include #include #include #include diff --git a/src/stan/model/model_header.hpp b/src/stan/model/model_header.hpp index 34948377f7..a3896ecc6c 100644 --- a/src/stan/model/model_header.hpp +++ b/src/stan/model/model_header.hpp @@ -1,14 +1,14 @@ #ifndef STAN_MODEL_MODEL_HEADER_HPP #define STAN_MODEL_MODEL_HEADER_HPP +#include +#include #include #include #include #include -#include -#include #include #include #include From 343eebb6aa6537b5eeeea31538a70a68c74ad602 Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Mon, 24 Jun 2024 12:12:17 -0400 Subject: [PATCH 3/3] [Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1 --- src/stan/model/model_base.hpp | 92 ++++++++++++----------------------- 1 file changed, 32 insertions(+), 60 deletions(-) diff --git a/src/stan/model/model_base.hpp b/src/stan/model/model_base.hpp index a8196d93d7..eab24bec11 100644 --- a/src/stan/model/model_base.hpp +++ b/src/stan/model/model_base.hpp @@ -78,8 +78,7 @@ class model_base : public prob_grad { */ virtual void get_param_names(std::vector& 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 @@ -108,8 +107,7 @@ class model_base : public prob_grad { */ virtual void get_dims(std::vector >& 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 @@ -150,8 +148,7 @@ class model_base : public prob_grad { */ virtual void constrained_param_names(std::vector& 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 @@ -180,8 +177,7 @@ class model_base : public prob_grad { */ virtual void unconstrained_param_names(std::vector& 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 @@ -192,8 +188,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 @@ -205,8 +201,7 @@ class model_base : public prob_grad { * @return log density for specified parameters */ virtual math::var log_prob(Eigen::Matrix& params_r, - std::ostream* msgs) const - = 0; + std::ostream* msgs) const = 0; /** * Return the log density for the specified unconstrained @@ -222,8 +217,7 @@ 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 @@ -239,8 +233,7 @@ class model_base : public prob_grad { * @return log density for specified parameters */ virtual math::var log_prob_jacobian(Eigen::Matrix& params_r, - std::ostream* msgs) const - = 0; + std::ostream* msgs) const = 0; /** * Return the log density for the specified unconstrained @@ -257,8 +250,7 @@ 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 @@ -270,8 +262,7 @@ class model_base : public prob_grad { * @return log density for specified parameters */ virtual math::var log_prob_propto(Eigen::Matrix& params_r, - std::ostream* msgs) const - = 0; + std::ostream* msgs) const = 0; /** * Return the log density for the specified unconstrained @@ -292,8 +283,7 @@ 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 @@ -309,8 +299,7 @@ class model_base : public prob_grad { * @return log density for specified parameters */ virtual math::var log_prob_propto_jacobian( - Eigen::Matrix& params_r, std::ostream* msgs) const - = 0; + Eigen::Matrix& params_r, std::ostream* msgs) const = 0; /** * Convenience template function returning the log density for the @@ -358,8 +347,7 @@ 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 @@ -382,8 +370,7 @@ 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 @@ -398,8 +385,7 @@ 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 === @@ -416,8 +402,8 @@ class model_base : public prob_grad { * @return log density for specified parameters */ virtual double log_prob(std::vector& params_r, - std::vector& params_i, std::ostream* msgs) const - = 0; + std::vector& params_i, + std::ostream* msgs) const = 0; /** * Return the log density for the specified unconstrained @@ -433,8 +419,7 @@ class model_base : public prob_grad { */ virtual math::var log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* msgs) const - = 0; + std::ostream* msgs) const = 0; /** * Return the log density for the specified unconstrained @@ -454,8 +439,7 @@ class model_base : public prob_grad { */ virtual double log_prob_jacobian(std::vector& params_r, std::vector& params_i, - std::ostream* msgs) const - = 0; + std::ostream* msgs) const = 0; /** * Return the log density for the specified unconstrained @@ -475,8 +459,7 @@ class model_base : public prob_grad { */ virtual math::var log_prob_jacobian(std::vector& params_r, std::vector& params_i, - std::ostream* msgs) const - = 0; + std::ostream* msgs) const = 0; /** * Return the log density for the specified unconstrained @@ -497,8 +480,7 @@ class model_base : public prob_grad { */ virtual double log_prob_propto(std::vector& params_r, std::vector& params_i, - std::ostream* msgs) const - = 0; + std::ostream* msgs) const = 0; /** * Return the log density for the specified unconstrained @@ -514,8 +496,7 @@ class model_base : public prob_grad { */ virtual math::var log_prob_propto(std::vector& params_r, std::vector& params_i, - std::ostream* msgs) const - = 0; + std::ostream* msgs) const = 0; /** * Return the log density for the specified unconstrained @@ -540,8 +521,7 @@ class model_base : public prob_grad { */ virtual double log_prob_propto_jacobian(std::vector& params_r, std::vector& params_i, - std::ostream* msgs) const - = 0; + std::ostream* msgs) const = 0; /** * Return the log density for the specified unconstrained @@ -561,8 +541,7 @@ class model_base : public prob_grad { */ virtual math::var log_prob_propto_jacobian(std::vector& params_r, std::vector& params_i, - std::ostream* msgs) const - = 0; + std::ostream* msgs) const = 0; /** * Convenience template function returning the log density for the @@ -617,8 +596,7 @@ class model_base : public prob_grad { virtual void transform_inits(const io::var_context& context, std::vector& params_i, std::vector& params_r, - std::ostream* msgs) const - = 0; + std::ostream* msgs) const = 0; /** * Convert the specified sequence of unconstrained parameters to a @@ -643,8 +621,7 @@ class model_base : public prob_grad { std::vector& params_i, std::vector& 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 @@ -659,8 +636,7 @@ class model_base : public prob_grad { */ virtual void unconstrain_array( const std::vector& params_r_constrained, - std::vector& params_r, std::ostream* msgs = nullptr) const - = 0; + std::vector& params_r, std::ostream* msgs = nullptr) const = 0; #ifdef STAN_MODEL_FVAR_VAR @@ -675,8 +651,7 @@ class model_base : public prob_grad { */ virtual math::fvar log_prob( Eigen::Matrix, -1, 1>& params_r, - std::ostream* msgs) const - = 0; + std::ostream* msgs) const = 0; /** * Return the log density for the specified unconstrained @@ -693,8 +668,7 @@ class model_base : public prob_grad { */ virtual math::fvar log_prob_jacobian( Eigen::Matrix, -1, 1>& params_r, - std::ostream* msgs) const - = 0; + std::ostream* msgs) const = 0; /** * Return the log density for the specified unconstrained @@ -707,8 +681,7 @@ class model_base : public prob_grad { */ virtual math::fvar log_prob_propto( Eigen::Matrix, -1, 1>& params_r, - std::ostream* msgs) const - = 0; + std::ostream* msgs) const = 0; /** * Return the log density for the specified unconstrained @@ -725,8 +698,7 @@ class model_base : public prob_grad { */ virtual math::fvar log_prob_propto_jacobian( Eigen::Matrix, -1, 1>& params_r, - std::ostream* msgs) const - = 0; + std::ostream* msgs) const = 0; #endif };