Skip to content

Commit 4c626fd

Browse files
authoredJun 18, 2024
Merge pull request #3086 from stan-dev/fix/3085-use-long-int-for-container-sizes
2 parents 44c91c9 + 7a0038a commit 4c626fd

17 files changed

+42
-31
lines changed
 

‎stan/math/opencl/prim/binomial_logit_glm_lpmf.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <stan/math/prim/fun/value_of_rec.hpp>
2121

2222
#include <cmath>
23+
#include <cstdint>
2324

2425
namespace stan {
2526
namespace math {
@@ -37,7 +38,7 @@ return_type_t<T_x_cl, T_alpha_cl, T_beta_cl> binomial_logit_glm_lpmf(
3738
constexpr bool is_alpha_vector = !is_stan_scalar<T_alpha_cl>::value;
3839

3940
const size_t N_instances
40-
= max(max_size(n, N, alpha), static_cast<size_t>(x.rows()));
41+
= max(max_size(n, N, alpha), static_cast<int64_t>(x.rows()));
4142
const size_t N_attributes = x.cols();
4243

4344
check_consistent_sizes(function, "Successes variable", n,

‎stan/math/opencl/prim/cols.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#ifdef STAN_OPENCL
44

55
#include <stan/math/opencl/matrix_cl.hpp>
6+
#include <cstdint>
67

78
namespace stan {
89
namespace math {
@@ -17,7 +18,7 @@ namespace math {
1718
*/
1819
template <typename T_x,
1920
require_nonscalar_prim_or_rev_kernel_expression_t<T_x>* = nullptr>
20-
inline int cols(const T_x& x) {
21+
inline int64_t cols(const T_x& x) {
2122
return x.cols();
2223
}
2324
} // namespace math

‎stan/math/opencl/prim/num_elements.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <stan/math/prim/meta.hpp>
66
#include <stan/math/opencl/prim/size.hpp>
7+
#include <cstdint>
78

89
namespace stan {
910
namespace math {
@@ -16,7 +17,7 @@ namespace math {
1617
*/
1718
template <typename T,
1819
require_nonscalar_prim_or_rev_kernel_expression_t<T>* = nullptr>
19-
size_t num_elements(const T& m) {
20+
int64_t num_elements(const T& m) {
2021
return math::size(m);
2122
}
2223

‎stan/math/opencl/prim/rows.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#ifdef STAN_OPENCL
44

55
#include <stan/math/opencl/matrix_cl.hpp>
6+
#include <cstdint>
67

78
namespace stan {
89
namespace math {
@@ -18,7 +19,7 @@ namespace math {
1819

1920
template <typename T_x,
2021
require_nonscalar_prim_or_rev_kernel_expression_t<T_x>* = nullptr>
21-
inline int rows(const T_x& x) {
22+
inline int64_t rows(const T_x& x) {
2223
return x.rows();
2324
}
2425

‎stan/math/opencl/prim/size.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#ifdef STAN_OPENCL
44

55
#include <stan/math/prim/meta.hpp>
6+
#include <cstdint>
67

78
namespace stan {
89
namespace math {
@@ -15,7 +16,7 @@ namespace math {
1516
*/
1617
template <typename T,
1718
require_nonscalar_prim_or_rev_kernel_expression_t<T>* = nullptr>
18-
size_t size(const T& m) {
19+
int64_t size(const T& m) {
1920
return m.rows() * m.cols();
2021
}
2122

‎stan/math/prim/fun/cols.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <stan/math/prim/fun/Eigen.hpp>
55
#include <stan/math/prim/meta.hpp>
6+
#include <cstdint>
67

78
namespace stan {
89
namespace math {
@@ -16,7 +17,7 @@ namespace math {
1617
* @return Number of columns.
1718
*/
1819
template <typename T, require_matrix_t<T>* = nullptr>
19-
inline Eigen::Index cols(const T& m) {
20+
inline int64_t cols(const T& m) {
2021
return m.cols();
2122
}
2223

‎stan/math/prim/fun/max_size.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define STAN_MATH_PRIM_FUN_MAX_SIZE_HPP
33

44
#include <stan/math/prim/fun/size.hpp>
5+
#include <cstdint>
56
#include <algorithm>
67

78
namespace stan {
@@ -16,7 +17,7 @@ namespace math {
1617
* @return the size of the largest input
1718
*/
1819
template <typename T1, typename... Ts>
19-
inline size_t max_size(const T1& x1, const Ts&... xs) {
20+
inline int64_t max_size(const T1& x1, const Ts&... xs) {
2021
return std::max({stan::math::size(x1), stan::math::size(xs)...});
2122
}
2223

‎stan/math/prim/fun/max_size_mvt.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <stan/math/prim/fun/size_mvt.hpp>
55
#include <algorithm>
6+
#include <cstdint>
67

78
namespace stan {
89
namespace math {
@@ -21,7 +22,7 @@ namespace math {
2122
* matrix or std::vector of Eigen matrices
2223
*/
2324
template <typename T1, typename... Ts>
24-
inline size_t max_size_mvt(const T1& x1, const Ts&... xs) {
25+
inline int64_t max_size_mvt(const T1& x1, const Ts&... xs) {
2526
return std::max({stan::math::size_mvt(x1), stan::math::size_mvt(xs)...});
2627
}
2728

‎stan/math/prim/fun/num_elements.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <stan/math/prim/fun/Eigen.hpp>
55
#include <stan/math/prim/meta.hpp>
6+
#include <cstdint>
67
#include <vector>
78

89
namespace stan {
@@ -16,7 +17,7 @@ namespace math {
1617
* @return 1
1718
*/
1819
template <typename T, require_stan_scalar_t<T>* = nullptr>
19-
inline int num_elements(const T& x) {
20+
inline int64_t num_elements(const T& x) {
2021
return 1;
2122
}
2223

@@ -29,7 +30,7 @@ inline int num_elements(const T& x) {
2930
* @return size of matrix
3031
*/
3132
template <typename T, require_matrix_t<T>* = nullptr>
32-
inline int num_elements(const T& m) {
33+
inline int64_t num_elements(const T& m) {
3334
return m.size();
3435
}
3536

@@ -43,7 +44,7 @@ inline int num_elements(const T& m) {
4344
* @return number of contained arguments
4445
*/
4546
template <typename T>
46-
inline int num_elements(const std::vector<T>& v) {
47+
inline int64_t num_elements(const std::vector<T>& v) {
4748
if (v.size() == 0) {
4849
return 0;
4950
}

‎stan/math/prim/fun/rows.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <stan/math/prim/fun/Eigen.hpp>
55
#include <stan/math/prim/meta.hpp>
6+
#include <cstdint>
67

78
namespace stan {
89
namespace math {
@@ -16,7 +17,7 @@ namespace math {
1617
* @return Number of rows.
1718
*/
1819
template <typename T, require_matrix_t<T>* = nullptr>
19-
inline int rows(const T& m) {
20+
inline int64_t rows(const T& m) {
2021
return m.rows();
2122
}
2223

‎stan/math/prim/fun/size.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/fun/Eigen.hpp>
6-
#include <cstdlib>
6+
#include <cstdint>
77
#include <vector>
88

99
namespace stan {
@@ -14,8 +14,8 @@ namespace math {
1414
* that are always of length 1.
1515
*/
1616
template <typename T, require_stan_scalar_t<T>* = nullptr>
17-
inline size_t size(const T& /*x*/) {
18-
return 1U;
17+
inline int64_t size(const T& /*x*/) {
18+
return 1;
1919
}
2020

2121
/** \ingroup type_trait
@@ -25,12 +25,12 @@ inline size_t size(const T& /*x*/) {
2525
* @tparam T type of m
2626
*/
2727
template <typename T, require_container_t<T>* = nullptr>
28-
inline size_t size(const T& m) {
28+
inline int64_t size(const T& m) {
2929
return m.size();
3030
}
3131

3232
template <typename T, require_var_matrix_t<T>* = nullptr>
33-
inline size_t size(const T& m) {
33+
inline int64_t size(const T& m) {
3434
return m.size();
3535
}
3636

‎stan/math/prim/fun/size_mvt.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/fun/Eigen.hpp>
6+
#include <cstdint>
67
#include <stdexcept>
78
#include <vector>
89

@@ -21,17 +22,17 @@ namespace math {
2122
* @throw std::invalid_argument since the type is a scalar.
2223
*/
2324
template <typename ScalarT, require_stan_scalar_t<ScalarT>* = nullptr>
24-
size_t size_mvt(const ScalarT& /* unused */) {
25+
int64_t size_mvt(const ScalarT& /* unused */) {
2526
throw std::invalid_argument("size_mvt passed to an unrecognized type.");
2627
}
2728

2829
template <typename MatrixT, require_matrix_t<MatrixT>* = nullptr>
29-
size_t size_mvt(const MatrixT& /* unused */) {
30-
return 1U;
30+
int64_t size_mvt(const MatrixT& /* unused */) {
31+
return 1;
3132
}
3233

3334
template <typename MatrixT, require_matrix_t<MatrixT>* = nullptr>
34-
size_t size_mvt(const std::vector<MatrixT>& x) {
35+
int64_t size_mvt(const std::vector<MatrixT>& x) {
3536
return x.size();
3637
}
3738

‎stan/math/prim/prob/poisson_binomial_cdf.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ return_type_t<T_theta> poisson_binomial_cdf(const T_y& y,
3737
const T_theta& theta) {
3838
static constexpr const char* function = "poisson_binomial_cdf";
3939

40-
size_t size_theta = size_mvt(theta);
40+
auto size_theta = size_mvt(theta);
4141
if (size_theta > 1) {
4242
check_consistent_sizes(function, "Successes variables", y,
4343
"Probability parameters", theta);
4444
}
4545

46-
size_t max_sz = std::max(stan::math::size(y), size_theta);
46+
auto max_sz = std::max(stan::math::size(y), size_theta);
4747
scalar_seq_view<T_y> y_vec(y);
4848
vector_seq_view<T_theta> theta_vec(theta);
4949

‎stan/math/prim/prob/poisson_binomial_lccdf.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ return_type_t<T_theta> poisson_binomial_lccdf(const T_y& y,
3838
const T_theta& theta) {
3939
static constexpr const char* function = "poisson_binomial_lccdf";
4040

41-
size_t size_theta = size_mvt(theta);
41+
auto size_theta = size_mvt(theta);
4242
if (size_theta > 1) {
4343
check_consistent_sizes(function, "Successes variables", y,
4444
"Probability parameters", theta);
4545
}
4646

47-
size_t max_sz = std::max(stan::math::size(y), size_mvt(theta));
47+
auto max_sz = std::max(stan::math::size(y), size_mvt(theta));
4848
scalar_seq_view<T_y> y_vec(y);
4949
vector_seq_view<T_theta> theta_vec(theta);
5050

‎stan/math/prim/prob/poisson_binomial_lcdf.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ return_type_t<T_theta> poisson_binomial_lcdf(const T_y& y,
3737
const T_theta& theta) {
3838
static constexpr const char* function = "poisson_binomial_lcdf";
3939

40-
size_t size_theta = size_mvt(theta);
40+
auto size_theta = size_mvt(theta);
4141
if (size_theta > 1) {
4242
check_consistent_sizes(function, "Successes variables", y,
4343
"Probability parameters", theta);
4444
}
4545

46-
size_t max_sz = std::max(stan::math::size(y), size_theta);
46+
auto max_sz = std::max(stan::math::size(y), size_theta);
4747
scalar_seq_view<T_y> y_vec(y);
4848
vector_seq_view<T_theta> theta_vec(theta);
4949

‎stan/math/prim/prob/poisson_binomial_lpmf.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ return_type_t<T_theta> poisson_binomial_lpmf(const T_y& y,
2929
const T_theta& theta) {
3030
static constexpr const char* function = "poisson_binomial_lpmf";
3131

32-
size_t size_theta = size_mvt(theta);
32+
auto size_theta = size_mvt(theta);
3333
if (size_theta > 1) {
3434
check_consistent_sizes(function, "Successes variables", y,
3535
"Probability parameters", theta);
3636
}
3737

38-
size_t max_sz = std::max(stan::math::size(y), size_theta);
38+
auto max_sz = std::max(stan::math::size(y), size_theta);
3939
scalar_seq_view<T_y> y_vec(y);
4040
vector_seq_view<T_theta> theta_vec(theta);
4141

‎test/unit/math/opencl/util.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ T to_vector_if(const T& x, std::size_t N) {
233233

234234
using stan::math::rows;
235235
template <typename T, require_not_container_t<T>* = nullptr>
236-
int rows(const T&) {
236+
int64_t rows(const T&) {
237237
return 1;
238238
}
239239
template <typename T, require_std_vector_t<T>* = nullptr>
240-
int rows(const T& x) {
240+
int64_t rows(const T& x) {
241241
return x.size();
242242
}
243243

0 commit comments

Comments
 (0)