Skip to content

Commit 3f12906

Browse files
committed
[Jenkins] auto-formatting by clang-format version 5.0.0-3~16.04.1 (tags/RELEASE_500/final)
1 parent 1d38cf3 commit 3f12906

File tree

2 files changed

+61
-32
lines changed

2 files changed

+61
-32
lines changed

stan/math/prim/scal/fun/lgamma_stirling_diff.hpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,58 @@
77
#include <stan/math/prim/scal/fun/lgamma.hpp>
88
#include <stan/math/prim/scal/fun/lgamma_stirling.hpp>
99

10-
1110
namespace stan {
1211
namespace math {
1312

1413
namespace internal {
15-
constexpr double lgamma_stirling_diff_big = 1e10;
14+
constexpr double lgamma_stirling_diff_big = 1e10;
1615
}
1716

18-
19-
// namespace lgamma_stirling_diff_internal {
17+
// namespace lgamma_stirling_diff_internal {
2018
// typedef long double Real;
2119

22-
// boost::math::chebyshev_transform<Real>
20+
// boost::math::chebyshev_transform<Real>
2321
// build_lgamma_stirling_diff_chebyshev() {
2422
// std::cout << "Size: " << sizeof(Real) << std::endl;
2523
// auto f = [](Real t) {
2624
// Real x = 10 * std::sqrt(2 / (t + 1));
2725
// if(x > internal::lgamma_stirling_diff_big) {
2826
// return 1.0 / (12.0 * x);
2927
// } else {
30-
// Real stirling = 0.5
31-
// * std::log(2* static_cast<Real>(stan::math::pi()))
28+
// Real stirling = 0.5
29+
// * std::log(2* static_cast<Real>(stan::math::pi()))
3230
// + (x - 0.5)*std::log(x) -x;
3331
// return (std::lgamma(x) - stirling);
3432
// }
3533
// };
36-
// auto transform = boost::math::chebyshev_transform<Real>(f, -1, 1, 1e-8);
37-
// std::cout << "Coeffs: " << transform.coefficients().size() << std::endl;
34+
// auto transform = boost::math::chebyshev_transform<Real>(f, -1, 1,
35+
// 1e-8); std::cout << "Coeffs: " << transform.coefficients().size() <<
36+
// std::endl;
3837
// //std::cout << transform.coefficients()[0];
39-
// size_t coeffs_to_print =
38+
// size_t coeffs_to_print =
4039
// std::min(size_t(20), transform.coefficients().size());
4140
// for(size_t i = 0; i < coeffs_to_print ; i ++) {
42-
// std::cout << std::setprecision(17) << transform.coefficients()[i]
41+
// std::cout << std::setprecision(17) << transform.coefficients()[i]
4342
// << std::endl;
4443
// }
4544
// return transform;
4645
// }
4746

48-
// boost::math::chebyshev_transform<Real> lgamma_stirling_diff_chebyshev =
47+
// boost::math::chebyshev_transform<Real> lgamma_stirling_diff_chebyshev =
4948
// build_lgamma_stirling_diff_chebyshev();
5049
// }
5150

51+
double lgamma_stirling_diff(const double x) {
52+
if (x < internal::lgamma_stirling_diff_big) {
53+
return std::lgamma(static_cast<long double>(x))
54+
- lgamma_stirling(static_cast<long double>(x));
5255

53-
double lgamma_stirling_diff(const double x) {
54-
if (x < internal::lgamma_stirling_diff_big) {
55-
return std::lgamma(static_cast<long double>(x)) - lgamma_stirling(static_cast<long double>(x));
56-
57-
// double ten_over_x = 10.0 / x;
58-
// double t = ten_over_x * ten_over_x * 2 - 1;
59-
// return internal::lgamma_stirling_diff_chebyshev(t);
60-
} else {
61-
return 1.0 / (12.0 * x);
62-
}
56+
// double ten_over_x = 10.0 / x;
57+
// double t = ten_over_x * ten_over_x * 2 - 1;
58+
// return internal::lgamma_stirling_diff_chebyshev(t);
59+
} else {
60+
return 1.0 / (12.0 * x);
61+
}
6362
}
6463

6564
} // namespace math

test/unit/math/prim/scal/fun/lgamma_stirling_diff_test.cpp

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ TEST(MathFunctions, lgamma_stirling_diff_accuracy) {
1616

1717
long double start = std::nextafter(10, 11);
1818
for (long double x = start; x < 2 * lgamma_stirling_diff_big; x *= 1.5) {
19-
long double stirling = 0.5
20-
* std::log(2 * static_cast<long double>(stan::math::pi()))
21-
+ (x - 0.5) * std::log(x) - x;
19+
long double stirling
20+
= 0.5 * std::log(2 * static_cast<long double>(stan::math::pi()))
21+
+ (x - 0.5) * std::log(x) - x;
2222
long double lgamma_res = std::lgamma(x);
2323
double diff_actual = static_cast<double>(lgamma_res - stirling);
2424
double diff = lgamma_stirling_diff(x);
@@ -37,20 +37,50 @@ TEST(MathFunctions, lgamma_stirling_diff_accuracy) {
3737
}
3838

3939
namespace lgamma_stirling_diff_test_internal {
40-
struct TestValue {
41-
double x;
42-
double val;
43-
};
40+
struct TestValue {
41+
double x;
42+
double val;
43+
};
4444

45-
std::vector<TestValue> testValues = { {10.049787068367863943,0.0082893206359322200849}, {10.135335283236612692,0.0082193992370778811855}, {10.367879441171442322,0.0080351590240775284273}, {11.,0.007573675487951840795}, {12.718281828459045235,0.0065508998676477812047}, {17.389056098930650227,0.0047917583976502091168}, {30.085536923187667741,0.0027697782366142911547}, {64.598150033144239078,0.0012900163188678122747}, {158.41315910257660342,0.00052604987562270910548}, {413.42879349273512261,0.0002015663117649479817}, {1106.6331584284585993,0.000075303482848309432847}, {2990.9579870417282747,0.000027861753118520084151}, {8113.0839275753840077,0.000010271474329002342817}, {22036.465794806716517,3.7816106313768371052e-6}, {59884.141715197818455,1.3915759823173656792e-6}, {162764.79141900392081,5.1198623858832122975e-7}, {442423.39200892050333,1.8835652643709875774e-7}, {1.2026142841647767777e6,6.9293483730078043652e-8}, {3.2690273724721106393e6,2.5491782061865871668e-8}, {8.8861205205078726368e6,9.3779206731455076929e-9}, {2.4154962753575298215e7,3.4499466707312036902e-9}, {6.5659979137330511139e7,1.2691647854325126115e-9}, {1.7848231096318726084e8,4.6689967696866715977e-10}, {4.8516520540979027797e8,1.717627983295846792e-10}, {1.3188157444832146972e9,6.318800308680570434e-11}, {3.5849128561315915617e9,2.3245567375731604902e-11}, {9.7448034562489026e9,8.5515663509760607976e-12}, {2.6489122139843472294e10,3.1459454523782780579e-12}, {7.2004899347385872524e10,1.1573286552529392289e-12},};
46-
}
45+
std::vector<TestValue> testValues = {
46+
{10.049787068367863943, 0.0082893206359322200849},
47+
{10.135335283236612692, 0.0082193992370778811855},
48+
{10.367879441171442322, 0.0080351590240775284273},
49+
{11., 0.007573675487951840795},
50+
{12.718281828459045235, 0.0065508998676477812047},
51+
{17.389056098930650227, 0.0047917583976502091168},
52+
{30.085536923187667741, 0.0027697782366142911547},
53+
{64.598150033144239078, 0.0012900163188678122747},
54+
{158.41315910257660342, 0.00052604987562270910548},
55+
{413.42879349273512261, 0.0002015663117649479817},
56+
{1106.6331584284585993, 0.000075303482848309432847},
57+
{2990.9579870417282747, 0.000027861753118520084151},
58+
{8113.0839275753840077, 0.000010271474329002342817},
59+
{22036.465794806716517, 3.7816106313768371052e-6},
60+
{59884.141715197818455, 1.3915759823173656792e-6},
61+
{162764.79141900392081, 5.1198623858832122975e-7},
62+
{442423.39200892050333, 1.8835652643709875774e-7},
63+
{1.2026142841647767777e6, 6.9293483730078043652e-8},
64+
{3.2690273724721106393e6, 2.5491782061865871668e-8},
65+
{8.8861205205078726368e6, 9.3779206731455076929e-9},
66+
{2.4154962753575298215e7, 3.4499466707312036902e-9},
67+
{6.5659979137330511139e7, 1.2691647854325126115e-9},
68+
{1.7848231096318726084e8, 4.6689967696866715977e-10},
69+
{4.8516520540979027797e8, 1.717627983295846792e-10},
70+
{1.3188157444832146972e9, 6.318800308680570434e-11},
71+
{3.5849128561315915617e9, 2.3245567375731604902e-11},
72+
{9.7448034562489026e9, 8.5515663509760607976e-12},
73+
{2.6489122139843472294e10, 3.1459454523782780579e-12},
74+
{7.2004899347385872524e10, 1.1573286552529392289e-12},
75+
};
76+
} // namespace lgamma_stirling_diff_test_internal
4777

4878
TEST(MathFunctions, lgamma_stirling_diff_precomputed) {
4979
using stan::math::lgamma_stirling_diff;
5080
using stan::test::expect_near_rel;
5181
using namespace lgamma_stirling_diff_test_internal;
5282

53-
for(TestValue t : testValues) {
83+
for (TestValue t : testValues) {
5484
std::ostringstream msg;
5585
msg << "x = " << t.x;
5686
expect_near_rel(msg.str(), lgamma_stirling_diff(t.x), t.val);

0 commit comments

Comments
 (0)