Skip to content

Commit 532317b

Browse files
authored
Merge pull request #2758 from stan-dev/fix_gamma_lpdf_check
Check that y is positive finite in gamma_lpdf
2 parents 0f398e3 + 5dfc858 commit 532317b

File tree

3 files changed

+4
-19
lines changed

3 files changed

+4
-19
lines changed

stan/math/opencl/prim/gamma_lpdf.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ return_type_t<T_y_cl, T_shape_cl, T_inv_scale_cl> gamma_lpdf(
7272

7373
auto check_y_not_nan
7474
= check_cl(function, "Random variable", y_val, "not NaN");
75-
auto y_not_nan_expr = !isnan(y_val);
75+
auto y_not_nan_expr = y_val > 0 && isfinite(y_val);
7676
auto check_alpha_pos_finite
7777
= check_cl(function, "Shape parameter", alpha_val, "positive finite");
7878
auto alpha_pos_finite_expr = alpha_val > 0 && isfinite(alpha_val);

stan/math/prim/prob/gamma_lpdf.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ return_type_t<T_y, T_shape, T_inv_scale> gamma_lpdf(const T_y& y,
6868
decltype(auto) alpha_val = to_ref(as_value_column_array_or_scalar(alpha_ref));
6969
decltype(auto) beta_val = to_ref(as_value_column_array_or_scalar(beta_ref));
7070

71-
check_not_nan(function, "Random variable", y_val);
71+
check_positive_finite(function, "Random variable", y_val);
7272
check_positive_finite(function, "Shape parameter", alpha_val);
7373
check_positive_finite(function, "Inverse scale parameter", beta_val);
7474

test/unit/math/opencl/rev/gamma_lpdf_test.cpp

+2-17
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ TEST(ProbDistributionsGamma, error_checking) {
99
int N = 3;
1010

1111
Eigen::VectorXd y(N);
12-
y << -2.0, 0.5, 1;
12+
y << 2.0, 0.5, 1;
1313
Eigen::VectorXd y_size(N - 1);
1414
y_size << 0.1, 0.5;
1515
Eigen::VectorXd y_value(N);
@@ -81,7 +81,7 @@ TEST(ProbDistributionsGamma, opencl_matches_cpu_small) {
8181
int N = 3;
8282

8383
Eigen::VectorXd y(N);
84-
y << 0, 0.5, 1;
84+
y << 0.1, 0.5, 1;
8585
Eigen::VectorXd alpha(N);
8686
alpha << 0.3, 0.8, 1.0;
8787
Eigen::VectorXd beta(N);
@@ -98,21 +98,6 @@ TEST(ProbDistributionsGamma, opencl_matches_cpu_small) {
9898
gamma_lpdf_functor_propto, y.transpose().eval(), alpha.transpose().eval(),
9999
beta.transpose().eval());
100100
}
101-
TEST(ProbDistributionsGamma, opencl_matches_cpu_small_negative_y) {
102-
int N = 3;
103-
104-
Eigen::VectorXd y(N);
105-
y << -10, 0.5, 1;
106-
Eigen::VectorXd alpha(N);
107-
alpha << 0.3, 0.8, 1.0;
108-
Eigen::VectorXd beta(N);
109-
beta << 0.3, 0.8, 1.0;
110-
111-
stan::math::test::compare_cpu_opencl_prim_rev(gamma_lpdf_functor, y, alpha,
112-
beta);
113-
stan::math::test::compare_cpu_opencl_prim_rev(gamma_lpdf_functor_propto, y,
114-
alpha, beta);
115-
}
116101

117102
TEST(ProbDistributionsGamma, opencl_broadcast_y) {
118103
int N = 3;

0 commit comments

Comments
 (0)