Skip to content

Commit 2122c49

Browse files
committed
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
1 parent 2ecb5d2 commit 2122c49

4 files changed

Lines changed: 47 additions & 52 deletions

File tree

stan/math/prim/prob/gamma_lccdf.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,9 @@ return_type_t<T_y, T_shape, T_inv_scale> gamma_lccdf(const T_y& y,
8585
if constexpr (is_any_autodiff_v<T_y, T_inv_scale>) {
8686
const T_partials_return log_y_dbl = log(y_dbl);
8787
const T_partials_return log_beta_dbl = log(beta_dbl);
88-
const T_partials_return log_pdf = alpha_dbl * log_beta_dbl
89-
- lgamma(alpha_dbl)
90-
+ (alpha_dbl - 1.0) * log_y_dbl
91-
- beta_y_dbl;
88+
const T_partials_return log_pdf
89+
= alpha_dbl * log_beta_dbl - lgamma(alpha_dbl)
90+
+ (alpha_dbl - 1.0) * log_y_dbl - beta_y_dbl;
9291
const T_partials_return common_term = exp(log_pdf - log_Qn);
9392

9493
if constexpr (is_autodiff_v<T_y>) {
@@ -104,9 +103,10 @@ return_type_t<T_y, T_shape, T_inv_scale> gamma_lccdf(const T_y& y,
104103
if constexpr (is_autodiff_v<T_shape>) {
105104
const T_partials_return digamma_val = digamma(alpha_dbl);
106105
const T_partials_return gamma_val = tgamma(alpha_dbl);
107-
// d/dalpha log(1-F(y)) = grad_upper_inc_gamma / (1-F(y))
108-
partials<1>(ops_partials)[n]
109-
+= grad_reg_inc_gamma(alpha_dbl, beta_y_dbl, gamma_val, digamma_val) / Qn;
106+
// d/dalpha log(1-F(y)) = grad_upper_inc_gamma / (1-F(y))
107+
partials<1>(ops_partials)[n]
108+
+= grad_reg_inc_gamma(alpha_dbl, beta_y_dbl, gamma_val, digamma_val)
109+
/ Qn;
110110
}
111111
}
112112
return ops_partials.build(P);

test/unit/math/prim/prob/gamma_lccdf_test.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ TEST(ProbGamma, lccdf_alpha_one) {
8686
using std::log;
8787

8888
// When alpha = 1, gamma becomes exponential
89-
// For exponential with rate beta: LCCDF(y) = log(1 - (1-exp(-beta*y))) = log(exp(-beta*y)) = -beta*y
89+
// For exponential with rate beta: LCCDF(y) = log(1 - (1-exp(-beta*y))) =
90+
// log(exp(-beta*y)) = -beta*y
9091
double y = 2.0;
9192
double alpha = 1.0;
9293
double beta = 3.0;
@@ -102,14 +103,14 @@ TEST(ProbGamma, lccdf_various_values) {
102103

103104
// Test a variety of parameter combinations
104105
std::vector<std::tuple<double, double, double>> test_cases = {
105-
{0.5, 0.5, 1.0}, // Small y, small alpha
106-
{1.0, 1.0, 1.0}, // All ones
107-
{2.0, 3.0, 0.5}, // Moderate values
108-
{10.0, 2.0, 0.1}, // Large y, small beta
109-
{0.1, 10.0, 2.0}, // Small y, large alpha
110-
{5.0, 5.0, 1.0}, // Equal alpha and y
111-
{0.01, 0.5, 10.0}, // Small y, large beta
112-
{100.0, 100.0, 1.0} // Large matched values
106+
{0.5, 0.5, 1.0}, // Small y, small alpha
107+
{1.0, 1.0, 1.0}, // All ones
108+
{2.0, 3.0, 0.5}, // Moderate values
109+
{10.0, 2.0, 0.1}, // Large y, small beta
110+
{0.1, 10.0, 2.0}, // Small y, large alpha
111+
{5.0, 5.0, 1.0}, // Equal alpha and y
112+
{0.01, 0.5, 10.0}, // Small y, large beta
113+
{100.0, 100.0, 1.0} // Large matched values
113114
};
114115

115116
for (const auto& test_case : test_cases) {
@@ -122,8 +123,8 @@ TEST(ProbGamma, lccdf_various_values) {
122123
// All results should be finite and <= 0
123124
EXPECT_TRUE(std::isfinite(result))
124125
<< "Failed for y=" << y << ", alpha=" << alpha << ", beta=" << beta;
125-
EXPECT_LE(result, 0.0)
126-
<< "Failed for y=" << y << ", alpha=" << alpha << ", beta=" << beta;
126+
EXPECT_LE(result, 0.0) << "Failed for y=" << y << ", alpha=" << alpha
127+
<< ", beta=" << beta;
127128
}
128129
}
129130

@@ -173,8 +174,8 @@ TEST(ProbGamma, lccdf_monotonic_in_y) {
173174
}
174175

175176
TEST(ProbGamma, lccdf_consistency_with_cdf) {
176-
using stan::math::gamma_lccdf;
177177
using stan::math::gamma_cdf;
178+
using stan::math::gamma_lccdf;
178179
using std::log;
179180

180181
// Test that lccdf(y) ≈ log(1 - cdf(y))
@@ -194,12 +195,12 @@ TEST(ProbGamma, lccdf_numerically_challenging) {
194195

195196
// Test cases that might cause numerical issues
196197
std::vector<std::tuple<double, double, double>> challenging_cases = {
197-
{1e-8, 1e-6, 1.0}, // Very small y and alpha
198-
{1e-6, 100.0, 1e-3}, // Very small y, large alpha, small beta
199-
{1000.0, 0.1, 1e-4}, // Large y, small alpha, very small beta
200-
{50.0, 50.0, 1.0}, // Matched moderate values
201-
{0.001, 0.001, 100.0}, // Small y and alpha, large beta
202-
{1e6, 10.0, 1e-6}, // Very large y, moderate alpha, very small beta
198+
{1e-8, 1e-6, 1.0}, // Very small y and alpha
199+
{1e-6, 100.0, 1e-3}, // Very small y, large alpha, small beta
200+
{1000.0, 0.1, 1e-4}, // Large y, small alpha, very small beta
201+
{50.0, 50.0, 1.0}, // Matched moderate values
202+
{0.001, 0.001, 100.0}, // Small y and alpha, large beta
203+
{1e6, 10.0, 1e-6}, // Very large y, moderate alpha, very small beta
203204
};
204205

205206
for (const auto& test_case : challenging_cases) {
@@ -214,8 +215,8 @@ TEST(ProbGamma, lccdf_numerically_challenging) {
214215
<< "NaN for y=" << y << ", alpha=" << alpha << ", beta=" << beta;
215216

216217
// Should be <= 0 (log of probability)
217-
EXPECT_LE(result, 0.0)
218-
<< "Positive value for y=" << y << ", alpha=" << alpha << ", beta=" << beta;
218+
EXPECT_LE(result, 0.0) << "Positive value for y=" << y
219+
<< ", alpha=" << alpha << ", beta=" << beta;
219220
}
220221
}
221222

test/unit/math/rev/prob/gamma_lccdf_test.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ TEST(ProbDistributionsGamma, lccdf_derivatives_all_params) {
115115
// Check all gradients are finite and not NaN
116116
for (size_t i = 0; i < grads.size(); ++i) {
117117
EXPECT_FALSE(std::isnan(grads[i])) << "Gradient " << i << " is NaN";
118-
EXPECT_TRUE(std::isfinite(grads[i])) << "Gradient " << i << " is not finite";
118+
EXPECT_TRUE(std::isfinite(grads[i]))
119+
<< "Gradient " << i << " is not finite";
119120
}
120121

121122
// d/dy should be negative
@@ -291,12 +292,8 @@ TEST(ProbDistributionsGamma, lccdf_various_parameter_combinations) {
291292
using stan::math::var;
292293

293294
std::vector<std::tuple<double, double, double>> test_cases = {
294-
{0.5, 0.5, 1.0},
295-
{1.0, 1.0, 1.0},
296-
{2.0, 3.0, 0.5},
297-
{10.0, 2.0, 0.1},
298-
{0.1, 10.0, 2.0},
299-
{5.0, 5.0, 1.0},
295+
{0.5, 0.5, 1.0}, {1.0, 1.0, 1.0}, {2.0, 3.0, 0.5},
296+
{10.0, 2.0, 0.1}, {0.1, 10.0, 2.0}, {5.0, 5.0, 1.0},
300297
};
301298

302299
for (const auto& test_case : test_cases) {
@@ -354,10 +351,10 @@ TEST(ProbDistributionsGamma, lccdf_numerically_challenging_derivatives) {
354351

355352
// Test numerically challenging cases
356353
std::vector<std::tuple<double, double, double>> challenging_cases = {
357-
{1e-6, 1e-5, 1.0}, // Very small y and alpha
358-
{0.001, 100.0, 0.01}, // Small y, large alpha, small beta
359-
{1000.0, 0.5, 1e-3}, // Large y, small alpha, very small beta
360-
{50.0, 50.0, 1.0}, // Matched moderate values
354+
{1e-6, 1e-5, 1.0}, // Very small y and alpha
355+
{0.001, 100.0, 0.01}, // Small y, large alpha, small beta
356+
{1000.0, 0.5, 1e-3}, // Large y, small alpha, very small beta
357+
{50.0, 50.0, 1.0}, // Matched moderate values
361358
};
362359

363360
for (const auto& test_case : challenging_cases) {

test/unit/math/rev/prob/gamma_lcdf_test.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ TEST(ProbDistributionsGamma, lcdf_derivatives_all_params) {
115115
// Check all gradients are finite and not NaN
116116
for (size_t i = 0; i < grads.size(); ++i) {
117117
EXPECT_FALSE(std::isnan(grads[i])) << "Gradient " << i << " is NaN";
118-
EXPECT_TRUE(std::isfinite(grads[i])) << "Gradient " << i << " is not finite";
118+
EXPECT_TRUE(std::isfinite(grads[i]))
119+
<< "Gradient " << i << " is not finite";
119120
}
120121

121122
// d/dy should be positive
@@ -290,12 +291,8 @@ TEST(ProbDistributionsGamma, lcdf_various_parameter_combinations) {
290291
using stan::math::var;
291292

292293
std::vector<std::tuple<double, double, double>> test_cases = {
293-
{0.5, 0.5, 1.0},
294-
{1.0, 1.0, 1.0},
295-
{2.0, 3.0, 0.5},
296-
{10.0, 2.0, 0.1},
297-
{0.1, 10.0, 2.0},
298-
{5.0, 5.0, 1.0},
294+
{0.5, 0.5, 1.0}, {1.0, 1.0, 1.0}, {2.0, 3.0, 0.5},
295+
{10.0, 2.0, 0.1}, {0.1, 10.0, 2.0}, {5.0, 5.0, 1.0},
299296
};
300297

301298
for (const auto& test_case : test_cases) {
@@ -326,8 +323,8 @@ TEST(ProbDistributionsGamma, lcdf_various_parameter_combinations) {
326323
}
327324

328325
TEST(ProbDistributionsGamma, lcdf_consistency_with_lccdf) {
329-
using stan::math::gamma_lcdf;
330326
using stan::math::gamma_lccdf;
327+
using stan::math::gamma_lcdf;
331328
using stan::math::var;
332329

333330
// Test that lcdf and lccdf derivatives are related
@@ -388,10 +385,11 @@ TEST(ProbDistributionsGamma, lcdf_numerically_challenging_derivatives) {
388385

389386
// Test numerically challenging cases
390387
std::vector<std::tuple<double, double, double>> challenging_cases = {
391-
{1e-6, 1e-5, 1.0}, // Very small y and alpha
392-
// {0.001, 100.0, 0.01}, // This case causes NaN - numerically too challenging
393-
{1000.0, 0.5, 1e-3}, // Large y, small alpha, very small beta
394-
{50.0, 50.0, 1.0}, // Matched moderate values
388+
{1e-6, 1e-5, 1.0}, // Very small y and alpha
389+
// {0.001, 100.0, 0.01}, // This case causes NaN - numerically too
390+
// challenging
391+
{1000.0, 0.5, 1e-3}, // Large y, small alpha, very small beta
392+
{50.0, 50.0, 1.0}, // Matched moderate values
395393
};
396394

397395
for (const auto& test_case : challenging_cases) {
@@ -437,7 +435,6 @@ TEST(ProbDistributionsGamma, lcdf_monotonic_derivative) {
437435
std::vector<double> grads;
438436
lcdf_var.grad(vars, grads);
439437

440-
EXPECT_GT(grads[0], 0.0)
441-
<< "d/dy should be positive for y=" << y_d;
438+
EXPECT_GT(grads[0], 0.0) << "d/dy should be positive for y=" << y_d;
442439
}
443440
}

0 commit comments

Comments
 (0)