Skip to content

Commit 9b2e93b

Browse files
authored
Merge pull request #1711 from stan-dev/bugfix/include_what_you_use
Bugfix/include what you use in /prim/fun
2 parents ae0fad9 + 9d94901 commit 9b2e93b

File tree

194 files changed

+306
-58
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+306
-58
lines changed

stan/math/prim/err/check_2F1_converges.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/err/check_not_nan.hpp>
6+
#include <stan/math/prim/fun/fabs.hpp>
7+
#include <stan/math/prim/fun/floor.hpp>
68
#include <stan/math/prim/fun/is_nonpositive_integer.hpp>
79
#include <stan/math/prim/fun/value_of_rec.hpp>
810
#include <cmath>

stan/math/prim/err/check_3F2_converges.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/err/check_not_nan.hpp>
6+
#include <stan/math/prim/fun/fabs.hpp>
7+
#include <stan/math/prim/fun/floor.hpp>
68
#include <stan/math/prim/fun/is_nonpositive_integer.hpp>
79
#include <stan/math/prim/fun/value_of_rec.hpp>
810
#include <cmath>

stan/math/prim/err/is_unit_vector.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <stan/math/prim/err/is_nonzero_size.hpp>
66
#include <stan/math/prim/err/constraint_tolerance.hpp>
77
#include <stan/math/prim/fun/Eigen.hpp>
8+
#include <stan/math/prim/fun/fabs.hpp>
89
#include <cmath>
910

1011
namespace stan {

stan/math/prim/fun/F32.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/err.hpp>
6+
#include <stan/math/prim/fun/exp.hpp>
7+
#include <stan/math/prim/fun/fabs.hpp>
68
#include <stan/math/prim/fun/is_inf.hpp>
9+
#include <stan/math/prim/fun/log.hpp>
710
#include <cmath>
811

912
namespace stan {

stan/math/prim/fun/beta.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define STAN_MATH_PRIM_FUN_BETA_HPP
33

44
#include <stan/math/prim/meta.hpp>
5+
#include <stan/math/prim/fun/exp.hpp>
56
#include <stan/math/prim/fun/lgamma.hpp>
67
#include <cmath>
78

stan/math/prim/fun/binary_log_loss.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define STAN_MATH_PRIM_FUN_BINARY_LOG_LOSS_HPP
33

44
#include <stan/math/prim/meta.hpp>
5+
#include <stan/math/prim/fun/log.hpp>
56
#include <stan/math/prim/fun/log1m.hpp>
67
#include <cmath>
78

stan/math/prim/fun/cholesky_corr_constrain.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stan/math/prim/err.hpp>
55
#include <stan/math/prim/fun/Eigen.hpp>
66
#include <stan/math/prim/fun/log1m.hpp>
7+
#include <stan/math/prim/fun/sqrt.hpp>
78
#include <stan/math/prim/fun/square.hpp>
89
#include <stan/math/prim/fun/corr_constrain.hpp>
910
#include <cmath>

stan/math/prim/fun/cholesky_corr_free.hpp

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

44
#include <stan/math/prim/err.hpp>
55
#include <stan/math/prim/fun/Eigen.hpp>
6-
#include <stan/math/prim/fun/square.hpp>
76
#include <stan/math/prim/fun/corr_free.hpp>
7+
#include <stan/math/prim/fun/square.hpp>
88
#include <cmath>
99

1010
namespace stan {
@@ -15,7 +15,6 @@ Eigen::Matrix<T, Eigen::Dynamic, 1> cholesky_corr_free(
1515
const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& x) {
1616
using Eigen::Dynamic;
1717
using Eigen::Matrix;
18-
using std::sqrt;
1918

2019
check_square("cholesky_corr_free", "x", x);
2120
// should validate lower-triangular, unit lengths
@@ -27,7 +26,7 @@ Eigen::Matrix<T, Eigen::Dynamic, 1> cholesky_corr_free(
2726
z(k++) = corr_free(x(i, 0));
2827
double sum_sqs = square(x(i, 0));
2928
for (int j = 1; j < i; ++j) {
30-
z(k++) = corr_free(x(i, j) / sqrt(1.0 - sum_sqs));
29+
z(k++) = corr_free(x(i, j) / std::sqrt(1.0 - sum_sqs));
3130
sum_sqs += square(x(i, j));
3231
}
3332
}

stan/math/prim/fun/cholesky_factor_constrain.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <stan/math/prim/err.hpp>
55
#include <stan/math/prim/fun/Eigen.hpp>
6+
#include <stan/math/prim/fun/exp.hpp>
67
#include <stan/math/prim/fun/sum.hpp>
78
#include <cmath>
89
#include <stdexcept>

stan/math/prim/fun/cholesky_factor_free.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <stan/math/prim/err.hpp>
55
#include <stan/math/prim/fun/Eigen.hpp>
6+
#include <stan/math/prim/fun/log.hpp>
67
#include <cmath>
78
#include <stdexcept>
89

stan/math/prim/fun/corr_constrain.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/fun/log1m.hpp>
66
#include <stan/math/prim/fun/square.hpp>
7+
#include <stan/math/prim/fun/tanh.hpp>
78
#include <cmath>
89

910
namespace stan {

stan/math/prim/fun/cov_matrix_constrain.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/err.hpp>
6+
#include <stan/math/prim/fun/constants.hpp>
67
#include <stan/math/prim/fun/Eigen.hpp>
8+
#include <stan/math/prim/fun/exp.hpp>
9+
#include <stan/math/prim/fun/log.hpp>
710
#include <stan/math/prim/fun/multiply_lower_tri_self_transpose.hpp>
8-
#include <stan/math/prim/fun/constants.hpp>
911
#include <cmath>
1012

1113
namespace stan {

stan/math/prim/fun/cov_matrix_free.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/err.hpp>
66
#include <stan/math/prim/fun/Eigen.hpp>
7+
#include <stan/math/prim/fun/log.hpp>
78
#include <cmath>
89

910
namespace stan {

stan/math/prim/fun/cov_matrix_free_lkj.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/err.hpp>
66
#include <stan/math/prim/fun/Eigen.hpp>
7+
#include <stan/math/prim/fun/factor_cov_matrix.hpp>
78

89
namespace stan {
910
namespace math {

stan/math/prim/fun/csr_to_dense_matrix.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <stan/math/prim/err.hpp>
55
#include <stan/math/prim/fun/csr_u_to_z.hpp>
66
#include <stan/math/prim/fun/Eigen.hpp>
7-
#include <stan/math/prim/fun/dot_product.hpp>
87
#include <vector>
98

109
namespace stan {

stan/math/prim/fun/distance.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stan/math/prim/fun/abs.hpp>
77
#include <stan/math/prim/fun/Eigen.hpp>
88
#include <stan/math/prim/fun/squared_distance.hpp>
9+
#include <stan/math/prim/fun/sqrt.hpp>
910
#include <cmath>
1011

1112
namespace stan {

stan/math/prim/fun/divide_columns.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/err.hpp>
66
#include <stan/math/prim/fun/Eigen.hpp>
7-
#include <stan/math/prim/fun/divide.hpp>
87
#include <vector>
98

109
namespace stan {

stan/math/prim/fun/finite_diff_stepsize.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define STAN_MATH_PRIM_FUN_FINITE_DIFF_STEPSIZE_HPP
33

44
#include <stan/math/prim/fun/constants.hpp>
5+
#include <stan/math/prim/fun/fabs.hpp>
56
#include <cmath>
67

78
namespace stan {

stan/math/prim/fun/gp_exponential_cov.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stan/math/prim/fun/distance.hpp>
77
#include <stan/math/prim/fun/divide_columns.hpp>
88
#include <stan/math/prim/fun/Eigen.hpp>
9+
#include <stan/math/prim/fun/exp.hpp>
910
#include <stan/math/prim/fun/size.hpp>
1011
#include <stan/math/prim/fun/square.hpp>
1112
#include <cmath>

stan/math/prim/fun/gp_matern32_cov.hpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/err.hpp>
66
#include <stan/math/prim/fun/Eigen.hpp>
7-
#include <stan/math/prim/fun/divide.hpp>
7+
#include <stan/math/prim/fun/exp.hpp>
88
#include <stan/math/prim/fun/divide_columns.hpp>
99
#include <stan/math/prim/fun/distance.hpp>
1010
#include <stan/math/prim/fun/size.hpp>
1111
#include <stan/math/prim/fun/square.hpp>
12-
#include <stan/math/prim/fun/squared_distance.hpp>
1312
#include <cmath>
1413
#include <vector>
1514

@@ -41,7 +40,6 @@ gp_matern32_cov(const std::vector<T_x> &x, const T_s &sigma,
4140
const T_l &length_scale) {
4241
using std::exp;
4342
using std::pow;
44-
using std::sqrt;
4543

4644
size_t x_size = size(x);
4745
Eigen::Matrix<return_type_t<T_x, T_s, T_l>, Eigen::Dynamic, Eigen::Dynamic>
@@ -66,15 +64,14 @@ gp_matern32_cov(const std::vector<T_x> &x, const T_s &sigma,
6664
check_positive_finite(function, "length scale", length_scale);
6765

6866
T_s sigma_sq = square(sigma);
69-
T_l root_3_inv_l = sqrt(3.0) / length_scale;
70-
T_l neg_root_3_inv_l = -1.0 * sqrt(3.0) / length_scale;
67+
T_l root_3_inv_l = std::sqrt(3.0) / length_scale;
7168

7269
for (size_t i = 0; i < x_size; ++i) {
7370
cov(i, i) = sigma_sq;
7471
for (size_t j = i + 1; j < x_size; ++j) {
7572
return_type_t<T_x> dist = distance(x[i], x[j]);
76-
cov(i, j) = sigma_sq * (1.0 + root_3_inv_l * dist)
77-
* exp(neg_root_3_inv_l * dist);
73+
cov(i, j)
74+
= sigma_sq * (1.0 + root_3_inv_l * dist) * exp(-root_3_inv_l * dist);
7875
cov(j, i) = cov(i, j);
7976
}
8077
}
@@ -130,16 +127,15 @@ gp_matern32_cov(const std::vector<Eigen::Matrix<T_x, -1, 1>> &x,
130127
"number of length scales", l_size);
131128

132129
T_s sigma_sq = square(sigma);
133-
double root_3 = sqrt(3.0);
134-
double neg_root_3 = -1.0 * sqrt(3.0);
130+
double root_3 = std::sqrt(3.0);
135131

136132
std::vector<Eigen::Matrix<return_type_t<T_x, T_l>, -1, 1>> x_new
137133
= divide_columns(x, length_scale);
138134

139135
for (size_t i = 0; i < x_size; ++i) {
140136
for (size_t j = i; j < x_size; ++j) {
141137
return_type_t<T_x, T_l> dist = distance(x_new[i], x_new[j]);
142-
cov(i, j) = sigma_sq * (1.0 + root_3 * dist) * exp(neg_root_3 * dist);
138+
cov(i, j) = sigma_sq * (1.0 + root_3 * dist) * exp(-root_3 * dist);
143139
cov(j, i) = cov(i, j);
144140
}
145141
}
@@ -209,14 +205,13 @@ gp_matern32_cov(const std::vector<T_x1> &x1, const std::vector<T_x2> &x2,
209205
check_positive_finite(function, "length scale", length_scale);
210206

211207
T_s sigma_sq = square(sigma);
212-
T_l root_3_inv_l_sq = sqrt(3.0) / length_scale;
213-
T_l neg_root_3_inv_l_sq = -1.0 * sqrt(3.0) / length_scale;
208+
T_l root_3_inv_l_sq = std::sqrt(3.0) / length_scale;
214209

215210
for (size_t i = 0; i < x1_size; ++i) {
216211
for (size_t j = 0; j < x2_size; ++j) {
217212
return_type_t<T_x1, T_x2> dist = distance(x1[i], x2[j]);
218213
cov(i, j) = sigma_sq * (1.0 + root_3_inv_l_sq * dist)
219-
* exp(neg_root_3_inv_l_sq * dist);
214+
* exp(-root_3_inv_l_sq * dist);
220215
}
221216
}
222217
return cov;
@@ -290,8 +285,7 @@ gp_matern32_cov(const std::vector<Eigen::Matrix<T_x1, -1, 1>> &x1,
290285
}
291286

292287
T_s sigma_sq = square(sigma);
293-
double root_3 = sqrt(3.0);
294-
double neg_root_3 = -1.0 * sqrt(3.0);
288+
double root_3 = std::sqrt(3.0);
295289

296290
std::vector<Eigen::Matrix<return_type_t<T_x1, T_l>, -1, 1>> x1_new
297291
= divide_columns(x1, length_scale);
@@ -301,7 +295,7 @@ gp_matern32_cov(const std::vector<Eigen::Matrix<T_x1, -1, 1>> &x1,
301295
for (size_t i = 0; i < x1_size; ++i) {
302296
for (size_t j = 0; j < x2_size; ++j) {
303297
return_type_t<T_x1, T_x2, T_l> dist = distance(x1_new[i], x2_new[j]);
304-
cov(i, j) = sigma_sq * (1.0 + root_3 * dist) * exp(neg_root_3 * dist);
298+
cov(i, j) = sigma_sq * (1.0 + root_3 * dist) * exp(-root_3 * dist);
305299
}
306300
}
307301
return cov;

stan/math/prim/fun/gp_matern52_cov.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/err.hpp>
6-
#include <stan/math/prim/fun/divide.hpp>
76
#include <stan/math/prim/fun/divide_columns.hpp>
87
#include <stan/math/prim/fun/Eigen.hpp>
8+
#include <stan/math/prim/fun/exp.hpp>
99
#include <stan/math/prim/fun/sqrt.hpp>
1010
#include <stan/math/prim/fun/square.hpp>
1111
#include <stan/math/prim/fun/squared_distance.hpp>
@@ -61,7 +61,6 @@ gp_matern52_cov(const std::vector<T_x> &x, const T_s &sigma,
6161
T_s sigma_sq = square(sigma);
6262
T_l root_5_inv_l = sqrt(5.0) / length_scale;
6363
T_l inv_l_sq_5_3 = 5.0 / (3.0 * square(length_scale));
64-
T_l neg_root_5_inv_l = -sqrt(5.0) / length_scale;
6564

6665
for (size_t i = 0; i < x_size; ++i) {
6766
cov(i, i) = sigma_sq;
@@ -70,7 +69,7 @@ gp_matern52_cov(const std::vector<T_x> &x, const T_s &sigma,
7069
return_type_t<T_x> dist = sqrt(sq_distance);
7170
cov(i, j) = sigma_sq
7271
* (1.0 + root_5_inv_l * dist + inv_l_sq_5_3 * sq_distance)
73-
* exp(neg_root_5_inv_l * dist);
72+
* exp(-root_5_inv_l * dist);
7473
cov(j, i) = cov(i, j);
7574
}
7675
}
@@ -127,7 +126,6 @@ gp_matern52_cov(const std::vector<Eigen::Matrix<T_x, Eigen::Dynamic, 1>> &x,
127126
T_s sigma_sq = square(sigma);
128127
double root_5 = sqrt(5.0);
129128
double five_thirds = 5.0 / 3.0;
130-
double neg_root_5 = -root_5;
131129

132130
std::vector<Eigen::Matrix<return_type_t<T_x, T_l>, -1, 1>> x_new
133131
= divide_columns(x, length_scale);
@@ -139,7 +137,7 @@ gp_matern52_cov(const std::vector<Eigen::Matrix<T_x, Eigen::Dynamic, 1>> &x,
139137
= squared_distance(x_new[i], x_new[j]);
140138
return_type_t<T_x, T_l> dist = sqrt(sq_distance);
141139
cov(i, j) = sigma_sq * (1.0 + root_5 * dist + five_thirds * sq_distance)
142-
* exp(neg_root_5 * dist);
140+
* exp(-root_5 * dist);
143141
cov(j, i) = cov(i, j);
144142
}
145143
}
@@ -198,15 +196,14 @@ gp_matern52_cov(const std::vector<T_x1> &x1, const std::vector<T_x2> &x2,
198196
T_s sigma_sq = square(sigma);
199197
T_l root_5_inv_l = sqrt(5.0) / length_scale;
200198
T_l inv_l_sq_5_3 = 5.0 / (3.0 * square(length_scale));
201-
T_l neg_root_5_inv_l = -sqrt(5.0) / length_scale;
202199

203200
for (size_t i = 0; i < x1_size; ++i) {
204201
for (size_t j = 0; j < x2_size; ++j) {
205202
return_type_t<T_x1, T_x2> sq_distance = squared_distance(x1[i], x2[j]);
206203
return_type_t<T_x1, T_x2> dist = sqrt(sq_distance);
207204
cov(i, j) = sigma_sq
208205
* (1.0 + root_5_inv_l * dist + inv_l_sq_5_3 * sq_distance)
209-
* exp(neg_root_5_inv_l * dist);
206+
* exp(-root_5_inv_l * dist);
210207
}
211208
}
212209
return cov;
@@ -288,7 +285,7 @@ gp_matern52_cov(const std::vector<Eigen::Matrix<T_x1, Eigen::Dynamic, 1>> &x1,
288285
= squared_distance(x1_new[i], x2_new[j]);
289286
return_type_t<T_x1, T_x2, T_l> dist = sqrt(sq_distance);
290287
cov(i, j) = sigma_sq * (1.0 + root_5 * dist + five_thirds * sq_distance)
291-
* exp(neg_root_5 * dist);
288+
* exp(-root_5 * dist);
292289
}
293290
}
294291
return cov;

stan/math/prim/fun/gp_periodic_cov.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#include <stan/math/prim/fun/constants.hpp>
77
#include <stan/math/prim/fun/distance.hpp>
88
#include <stan/math/prim/fun/Eigen.hpp>
9-
#include <stan/math/prim/fun/inv.hpp>
9+
#include <stan/math/prim/fun/exp.hpp>
1010
#include <stan/math/prim/fun/inv_square.hpp>
11+
#include <stan/math/prim/fun/sin.hpp>
1112
#include <stan/math/prim/fun/square.hpp>
1213
#include <cmath>
1314
#include <vector>

stan/math/prim/fun/grad_2F1.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/err.hpp>
66
#include <stan/math/prim/fun/constants.hpp>
7+
#include <stan/math/prim/fun/exp.hpp>
8+
#include <stan/math/prim/fun/fabs.hpp>
9+
#include <stan/math/prim/fun/inv.hpp>
10+
#include <stan/math/prim/fun/log.hpp>
711
#include <cmath>
812

913
namespace stan {

stan/math/prim/fun/grad_F32.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/err.hpp>
66
#include <stan/math/prim/fun/constants.hpp>
7+
#include <stan/math/prim/fun/exp.hpp>
8+
#include <stan/math/prim/fun/fabs.hpp>
79
#include <stan/math/prim/fun/inv.hpp>
10+
#include <stan/math/prim/fun/log.hpp>
811
#include <cmath>
912

1013
namespace stan {

stan/math/prim/fun/grad_inc_beta.hpp

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

44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/fun/beta.hpp>
6+
#include <stan/math/prim/fun/exp.hpp>
67
#include <stan/math/prim/fun/fma.hpp>
7-
#include <stan/math/prim/fun/log1m.hpp>
8+
#include <stan/math/prim/fun/grad_2F1.hpp>
89
#include <stan/math/prim/fun/inv.hpp>
910
#include <stan/math/prim/fun/inc_beta.hpp>
10-
#include <stan/math/prim/fun/grad_2F1.hpp>
11+
#include <stan/math/prim/fun/log.hpp>
12+
#include <stan/math/prim/fun/log1m.hpp>
1113
#include <cmath>
1214

1315
namespace stan {

0 commit comments

Comments
 (0)