diff --git a/stan/math/opencl/prim/binomial_logit_glm_lpmf.hpp b/stan/math/opencl/prim/binomial_logit_glm_lpmf.hpp index a94052b860d..db189db081c 100644 --- a/stan/math/opencl/prim/binomial_logit_glm_lpmf.hpp +++ b/stan/math/opencl/prim/binomial_logit_glm_lpmf.hpp @@ -20,6 +20,7 @@ #include #include +#include namespace stan { namespace math { @@ -37,7 +38,7 @@ return_type_t binomial_logit_glm_lpmf( constexpr bool is_alpha_vector = !is_stan_scalar::value; const size_t N_instances - = max(max_size(n, N, alpha), static_cast(x.rows())); + = max(max_size(n, N, alpha), static_cast(x.rows())); const size_t N_attributes = x.cols(); check_consistent_sizes(function, "Successes variable", n, diff --git a/stan/math/opencl/prim/cols.hpp b/stan/math/opencl/prim/cols.hpp index d52e31b8e2c..1e4c934b4bd 100644 --- a/stan/math/opencl/prim/cols.hpp +++ b/stan/math/opencl/prim/cols.hpp @@ -3,6 +3,7 @@ #ifdef STAN_OPENCL #include +#include namespace stan { namespace math { @@ -17,7 +18,7 @@ namespace math { */ template * = nullptr> -inline int cols(const T_x& x) { +inline int64_t cols(const T_x& x) { return x.cols(); } } // namespace math diff --git a/stan/math/opencl/prim/num_elements.hpp b/stan/math/opencl/prim/num_elements.hpp index aedae05f616..71f73d84d29 100644 --- a/stan/math/opencl/prim/num_elements.hpp +++ b/stan/math/opencl/prim/num_elements.hpp @@ -4,6 +4,7 @@ #include #include +#include namespace stan { namespace math { @@ -16,7 +17,7 @@ namespace math { */ template * = nullptr> -size_t num_elements(const T& m) { +int64_t num_elements(const T& m) { return math::size(m); } diff --git a/stan/math/opencl/prim/rows.hpp b/stan/math/opencl/prim/rows.hpp index 23e7fabe133..a9984051d59 100644 --- a/stan/math/opencl/prim/rows.hpp +++ b/stan/math/opencl/prim/rows.hpp @@ -3,6 +3,7 @@ #ifdef STAN_OPENCL #include +#include namespace stan { namespace math { @@ -18,7 +19,7 @@ namespace math { template * = nullptr> -inline int rows(const T_x& x) { +inline int64_t rows(const T_x& x) { return x.rows(); } diff --git a/stan/math/opencl/prim/size.hpp b/stan/math/opencl/prim/size.hpp index 37d037a2943..f7b78a128b1 100644 --- a/stan/math/opencl/prim/size.hpp +++ b/stan/math/opencl/prim/size.hpp @@ -3,6 +3,7 @@ #ifdef STAN_OPENCL #include +#include namespace stan { namespace math { @@ -15,7 +16,7 @@ namespace math { */ template * = nullptr> -size_t size(const T& m) { +int64_t size(const T& m) { return m.rows() * m.cols(); } diff --git a/stan/math/prim/fun/cols.hpp b/stan/math/prim/fun/cols.hpp index 60cde07830e..07a24d5867a 100644 --- a/stan/math/prim/fun/cols.hpp +++ b/stan/math/prim/fun/cols.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace stan { namespace math { @@ -16,7 +17,7 @@ namespace math { * @return Number of columns. */ template * = nullptr> -inline Eigen::Index cols(const T& m) { +inline int64_t cols(const T& m) { return m.cols(); } diff --git a/stan/math/prim/fun/max_size.hpp b/stan/math/prim/fun/max_size.hpp index 9b0c8f2af8f..bbbcfefc7b3 100644 --- a/stan/math/prim/fun/max_size.hpp +++ b/stan/math/prim/fun/max_size.hpp @@ -2,6 +2,7 @@ #define STAN_MATH_PRIM_FUN_MAX_SIZE_HPP #include +#include #include namespace stan { @@ -16,7 +17,7 @@ namespace math { * @return the size of the largest input */ template -inline size_t max_size(const T1& x1, const Ts&... xs) { +inline int64_t max_size(const T1& x1, const Ts&... xs) { return std::max({stan::math::size(x1), stan::math::size(xs)...}); } diff --git a/stan/math/prim/fun/max_size_mvt.hpp b/stan/math/prim/fun/max_size_mvt.hpp index 72e45f76ea8..3cd661a9a9e 100644 --- a/stan/math/prim/fun/max_size_mvt.hpp +++ b/stan/math/prim/fun/max_size_mvt.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace stan { namespace math { @@ -21,7 +22,7 @@ namespace math { * matrix or std::vector of Eigen matrices */ template -inline size_t max_size_mvt(const T1& x1, const Ts&... xs) { +inline int64_t max_size_mvt(const T1& x1, const Ts&... xs) { return std::max({stan::math::size_mvt(x1), stan::math::size_mvt(xs)...}); } diff --git a/stan/math/prim/fun/num_elements.hpp b/stan/math/prim/fun/num_elements.hpp index 27bcadd1b62..574d2739fa1 100644 --- a/stan/math/prim/fun/num_elements.hpp +++ b/stan/math/prim/fun/num_elements.hpp @@ -3,6 +3,7 @@ #include #include +#include #include namespace stan { @@ -16,7 +17,7 @@ namespace math { * @return 1 */ template * = nullptr> -inline int num_elements(const T& x) { +inline int64_t num_elements(const T& x) { return 1; } @@ -29,7 +30,7 @@ inline int num_elements(const T& x) { * @return size of matrix */ template * = nullptr> -inline int num_elements(const T& m) { +inline int64_t num_elements(const T& m) { return m.size(); } @@ -43,7 +44,7 @@ inline int num_elements(const T& m) { * @return number of contained arguments */ template -inline int num_elements(const std::vector& v) { +inline int64_t num_elements(const std::vector& v) { if (v.size() == 0) { return 0; } diff --git a/stan/math/prim/fun/rows.hpp b/stan/math/prim/fun/rows.hpp index b42d3fc6ae0..b6e5f9925fe 100644 --- a/stan/math/prim/fun/rows.hpp +++ b/stan/math/prim/fun/rows.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace stan { namespace math { @@ -16,7 +17,7 @@ namespace math { * @return Number of rows. */ template * = nullptr> -inline int rows(const T& m) { +inline int64_t rows(const T& m) { return m.rows(); } diff --git a/stan/math/prim/fun/size.hpp b/stan/math/prim/fun/size.hpp index b5540638290..a9005d97b39 100644 --- a/stan/math/prim/fun/size.hpp +++ b/stan/math/prim/fun/size.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include namespace stan { @@ -14,8 +14,8 @@ namespace math { * that are always of length 1. */ template * = nullptr> -inline size_t size(const T& /*x*/) { - return 1U; +inline int64_t size(const T& /*x*/) { + return 1; } /** \ingroup type_trait @@ -25,12 +25,12 @@ inline size_t size(const T& /*x*/) { * @tparam T type of m */ template * = nullptr> -inline size_t size(const T& m) { +inline int64_t size(const T& m) { return m.size(); } template * = nullptr> -inline size_t size(const T& m) { +inline int64_t size(const T& m) { return m.size(); } diff --git a/stan/math/prim/fun/size_mvt.hpp b/stan/math/prim/fun/size_mvt.hpp index 6543412964f..b413388c711 100644 --- a/stan/math/prim/fun/size_mvt.hpp +++ b/stan/math/prim/fun/size_mvt.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -21,17 +22,17 @@ namespace math { * @throw std::invalid_argument since the type is a scalar. */ template * = nullptr> -size_t size_mvt(const ScalarT& /* unused */) { +int64_t size_mvt(const ScalarT& /* unused */) { throw std::invalid_argument("size_mvt passed to an unrecognized type."); } template * = nullptr> -size_t size_mvt(const MatrixT& /* unused */) { - return 1U; +int64_t size_mvt(const MatrixT& /* unused */) { + return 1; } template * = nullptr> -size_t size_mvt(const std::vector& x) { +int64_t size_mvt(const std::vector& x) { return x.size(); } diff --git a/stan/math/prim/prob/poisson_binomial_cdf.hpp b/stan/math/prim/prob/poisson_binomial_cdf.hpp index 0c4f647e835..f47abf7472d 100644 --- a/stan/math/prim/prob/poisson_binomial_cdf.hpp +++ b/stan/math/prim/prob/poisson_binomial_cdf.hpp @@ -37,13 +37,13 @@ return_type_t poisson_binomial_cdf(const T_y& y, const T_theta& theta) { static constexpr const char* function = "poisson_binomial_cdf"; - size_t size_theta = size_mvt(theta); + auto size_theta = size_mvt(theta); if (size_theta > 1) { check_consistent_sizes(function, "Successes variables", y, "Probability parameters", theta); } - size_t max_sz = std::max(stan::math::size(y), size_theta); + auto max_sz = std::max(stan::math::size(y), size_theta); scalar_seq_view y_vec(y); vector_seq_view theta_vec(theta); diff --git a/stan/math/prim/prob/poisson_binomial_lccdf.hpp b/stan/math/prim/prob/poisson_binomial_lccdf.hpp index 2f07bdb60e6..8d946f1a4c6 100644 --- a/stan/math/prim/prob/poisson_binomial_lccdf.hpp +++ b/stan/math/prim/prob/poisson_binomial_lccdf.hpp @@ -38,13 +38,13 @@ return_type_t poisson_binomial_lccdf(const T_y& y, const T_theta& theta) { static constexpr const char* function = "poisson_binomial_lccdf"; - size_t size_theta = size_mvt(theta); + auto size_theta = size_mvt(theta); if (size_theta > 1) { check_consistent_sizes(function, "Successes variables", y, "Probability parameters", theta); } - size_t max_sz = std::max(stan::math::size(y), size_mvt(theta)); + auto max_sz = std::max(stan::math::size(y), size_mvt(theta)); scalar_seq_view y_vec(y); vector_seq_view theta_vec(theta); diff --git a/stan/math/prim/prob/poisson_binomial_lcdf.hpp b/stan/math/prim/prob/poisson_binomial_lcdf.hpp index de5e91a32ce..7d449aa0caa 100644 --- a/stan/math/prim/prob/poisson_binomial_lcdf.hpp +++ b/stan/math/prim/prob/poisson_binomial_lcdf.hpp @@ -37,13 +37,13 @@ return_type_t poisson_binomial_lcdf(const T_y& y, const T_theta& theta) { static constexpr const char* function = "poisson_binomial_lcdf"; - size_t size_theta = size_mvt(theta); + auto size_theta = size_mvt(theta); if (size_theta > 1) { check_consistent_sizes(function, "Successes variables", y, "Probability parameters", theta); } - size_t max_sz = std::max(stan::math::size(y), size_theta); + auto max_sz = std::max(stan::math::size(y), size_theta); scalar_seq_view y_vec(y); vector_seq_view theta_vec(theta); diff --git a/stan/math/prim/prob/poisson_binomial_lpmf.hpp b/stan/math/prim/prob/poisson_binomial_lpmf.hpp index ac8b8a80c46..709a709c756 100644 --- a/stan/math/prim/prob/poisson_binomial_lpmf.hpp +++ b/stan/math/prim/prob/poisson_binomial_lpmf.hpp @@ -29,13 +29,13 @@ return_type_t poisson_binomial_lpmf(const T_y& y, const T_theta& theta) { static constexpr const char* function = "poisson_binomial_lpmf"; - size_t size_theta = size_mvt(theta); + auto size_theta = size_mvt(theta); if (size_theta > 1) { check_consistent_sizes(function, "Successes variables", y, "Probability parameters", theta); } - size_t max_sz = std::max(stan::math::size(y), size_theta); + auto max_sz = std::max(stan::math::size(y), size_theta); scalar_seq_view y_vec(y); vector_seq_view theta_vec(theta); diff --git a/test/unit/math/opencl/util.hpp b/test/unit/math/opencl/util.hpp index 484185c4831..9170a8d848c 100644 --- a/test/unit/math/opencl/util.hpp +++ b/test/unit/math/opencl/util.hpp @@ -233,11 +233,11 @@ T to_vector_if(const T& x, std::size_t N) { using stan::math::rows; template * = nullptr> -int rows(const T&) { +int64_t rows(const T&) { return 1; } template * = nullptr> -int rows(const T& x) { +int64_t rows(const T& x) { return x.size(); }