Skip to content

Commit 9872fcf

Browse files
committed
Tidy includes
1 parent 53ce103 commit 9872fcf

3 files changed

Lines changed: 16 additions & 35 deletions

File tree

stan/math/prim/prob/bernoulli_cdf.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33

44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/err.hpp>
6-
#include <stan/math/prim/fun/constants.hpp>
6+
#include <stan/math/prim/fun/any.hpp>
77
#include <stan/math/prim/fun/select.hpp>
8-
#include <stan/math/prim/fun/max_size.hpp>
9-
#include <stan/math/prim/fun/scalar_seq_view.hpp>
108
#include <stan/math/prim/fun/size.hpp>
119
#include <stan/math/prim/fun/size_zero.hpp>
12-
#include <stan/math/prim/fun/value_of.hpp>
1310
#include <stan/math/prim/functor/partials_propagator.hpp>
1411

1512
namespace stan {
@@ -38,8 +35,8 @@ return_type_t<T_prob> bernoulli_cdf(const T_n& n, const T_prob& theta) {
3835
"Probability parameter", theta);
3936
T_theta_ref theta_ref = theta;
4037
const auto& n_arr = as_array_or_scalar(n);
41-
check_bounded(function, "Probability parameter", value_of(theta_ref), 0.0,
42-
1.0);
38+
const auto& theta_arr = as_value_column_array_or_scalar(theta_ref);
39+
check_bounded(function, "Probability parameter", theta_arr, 0.0, 1.0);
4340

4441
if (size_zero(n, theta)) {
4542
return 1.0;
@@ -49,10 +46,9 @@ return_type_t<T_prob> bernoulli_cdf(const T_n& n, const T_prob& theta) {
4946

5047
// Explicit return for extreme values
5148
// The gradients are technically ill-defined, but treated as zero
52-
if (sum(n_arr < 0)) {
49+
if (any(n_arr < 0)) {
5350
return ops_partials.build(0.0);
5451
}
55-
const auto& theta_arr = as_value_column_array_or_scalar(theta_ref);
5652
const auto& log1m_theta = select(theta_arr == 1, 0.0, log1m(theta_arr));
5753
const auto& P1 = select(n_arr == 0, log1m_theta, 0.0);
5854

stan/math/prim/prob/bernoulli_lccdf.hpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@
33

44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/err.hpp>
6-
#include <stan/math/prim/fun/constants.hpp>
6+
#include <stan/math/prim/fun/any.hpp>
77
#include <stan/math/prim/fun/inv.hpp>
88
#include <stan/math/prim/fun/log.hpp>
9-
#include <stan/math/prim/fun/max_size.hpp>
10-
#include <stan/math/prim/fun/scalar_seq_view.hpp>
119
#include <stan/math/prim/fun/select.hpp>
12-
#include <stan/math/prim/fun/size.hpp>
1310
#include <stan/math/prim/fun/size_zero.hpp>
14-
#include <stan/math/prim/fun/value_of.hpp>
1511
#include <stan/math/prim/functor/partials_propagator.hpp>
16-
#include <cmath>
1712

1813
namespace stan {
1914
namespace math {
@@ -35,14 +30,13 @@ template <typename T_n, typename T_prob,
3530
T_n, T_prob>* = nullptr>
3631
return_type_t<T_prob> bernoulli_lccdf(const T_n& n, const T_prob& theta) {
3732
using T_theta_ref = ref_type_t<T_prob>;
38-
using std::log;
3933
static const char* function = "bernoulli_lccdf";
4034
check_consistent_sizes(function, "Random variable", n,
4135
"Probability parameter", theta);
4236
T_theta_ref theta_ref = theta;
4337
const auto& n_arr = as_array_or_scalar(n);
44-
check_bounded(function, "Probability parameter", value_of(theta_ref), 0.0,
45-
1.0);
38+
const auto& theta_arr = as_value_column_array_or_scalar(theta_ref);
39+
check_bounded(function, "Probability parameter", theta_arr, 0.0, 1.0);
4640

4741
if (size_zero(n, theta)) {
4842
return 0.0;
@@ -52,19 +46,19 @@ return_type_t<T_prob> bernoulli_lccdf(const T_n& n, const T_prob& theta) {
5246

5347
// Explicit return for extreme values
5448
// The gradients are technically ill-defined, but treated as zero
55-
if (sum(n_arr < 0)) {
49+
if (any(n_arr < 0)) {
5650
return ops_partials.build(0.0);
57-
} else if (sum(n_arr >= 1)) {
51+
} else if (any(n_arr >= 1)) {
5852
return ops_partials.build(NEGATIVE_INFTY);
5953
}
6054

61-
const auto& theta_arr = as_value_column_array_or_scalar(theta_ref);
55+
const auto& theta_broadcast = select(true, theta_arr, n_arr);
6256

6357
if (!is_constant_all<T_prob>::value) {
64-
partials<0>(ops_partials) = select(true, inv(theta_arr), n_arr);
58+
partials<0>(ops_partials) = inv(theta_broadcast);
6559
}
6660

67-
return ops_partials.build(sum(select(true, log(theta_arr), n_arr)));
61+
return ops_partials.build(sum(log(theta_broadcast)));
6862
}
6963

7064
} // namespace math

stan/math/prim/prob/bernoulli_lcdf.hpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,10 @@
33

44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/err.hpp>
6-
#include <stan/math/prim/fun/constants.hpp>
7-
#include <stan/math/prim/fun/inv.hpp>
8-
#include <stan/math/prim/fun/log.hpp>
9-
#include <stan/math/prim/fun/max_size.hpp>
10-
#include <stan/math/prim/fun/scalar_seq_view.hpp>
6+
#include <stan/math/prim/fun/any.hpp>
117
#include <stan/math/prim/fun/select.hpp>
12-
#include <stan/math/prim/fun/size.hpp>
138
#include <stan/math/prim/fun/size_zero.hpp>
14-
#include <stan/math/prim/fun/value_of.hpp>
159
#include <stan/math/prim/functor/partials_propagator.hpp>
16-
#include <cmath>
1710

1811
namespace stan {
1912
namespace math {
@@ -35,14 +28,13 @@ template <typename T_n, typename T_prob,
3528
T_n, T_prob>* = nullptr>
3629
return_type_t<T_prob> bernoulli_lcdf(const T_n& n, const T_prob& theta) {
3730
using T_theta_ref = ref_type_t<T_prob>;
38-
using std::log;
3931
static const char* function = "bernoulli_lcdf";
4032
check_consistent_sizes(function, "Random variable", n,
4133
"Probability parameter", theta);
4234
T_theta_ref theta_ref = theta;
4335
const auto& n_arr = as_array_or_scalar(n);
44-
check_bounded(function, "Probability parameter", value_of(theta_ref), 0.0,
45-
1.0);
36+
const auto& theta_arr = as_value_column_array_or_scalar(theta_ref);
37+
check_bounded(function, "Probability parameter", theta_arr, 0.0, 1.0);
4638

4739
if (size_zero(n, theta)) {
4840
return 0.0;
@@ -52,11 +44,10 @@ return_type_t<T_prob> bernoulli_lcdf(const T_n& n, const T_prob& theta) {
5244

5345
// Explicit return for extreme values
5446
// The gradients are technically ill-defined, but treated as zero
55-
if (sum(n_arr < 0)) {
47+
if (any(n_arr < 0)) {
5648
return ops_partials.build(NEGATIVE_INFTY);
5749
}
5850

59-
const auto& theta_arr = as_value_column_array_or_scalar(theta_ref);
6051
const auto& log1m_theta = select(theta_arr == 1, 0.0, log1m(theta_arr));
6152

6253
if (!is_constant_all<T_prob>::value) {

0 commit comments

Comments
 (0)