Skip to content

Commit 4c626fd

Browse files
authored
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

0 commit comments

Comments
 (0)