Skip to content

Commit 132cd2c

Browse files
committed
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.04.1 (tags/RELEASE_600/final)
1 parent 7f53b90 commit 132cd2c

File tree

5 files changed

+279
-298
lines changed

5 files changed

+279
-298
lines changed

stan/math/prim/functor/integrate_1d.hpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ inline double integrate(const F& f, double a, double b,
146146
* @return numeric integral of function f
147147
*/
148148
template <typename F, typename... Args,
149-
require_all_not_st_var<Args...>* = nullptr>
149+
require_all_not_st_var<Args...>* = nullptr>
150150
inline double integrate_1d_impl(const F& f, double a, double b,
151-
double relative_tolerance,
152-
std::ostream* msgs, const Args&... args) {
151+
double relative_tolerance, std::ostream* msgs,
152+
const Args&... args) {
153153
static const char* function = "integrate_1d";
154154
check_less_or_equal(function, "lower limit", a, b);
155155

@@ -159,10 +159,9 @@ inline double integrate_1d_impl(const F& f, double a, double b,
159159
}
160160
return 0.0;
161161
} else {
162-
return integrate(
163-
std::bind<double>(f, std::placeholders::_1, std::placeholders::_2,
164-
msgs, args...),
165-
a, b, relative_tolerance);
162+
return integrate(std::bind<double>(f, std::placeholders::_1,
163+
std::placeholders::_2, msgs, args...),
164+
a, b, relative_tolerance);
166165
}
167166
}
168167

@@ -219,9 +218,8 @@ inline double integrate_1d(const F& f, double a, double b,
219218
const std::vector<int>& x_i, std::ostream* msgs,
220219
const double relative_tolerance
221220
= std::sqrt(EPSILON)) {
222-
return integrate_1d_impl(integrate_1d_adapter<F>(f), a, b,
223-
relative_tolerance, msgs,
224-
theta, x_r, x_i);
221+
return integrate_1d_impl(integrate_1d_adapter<F>(f), a, b, relative_tolerance,
222+
msgs, theta, x_r, x_i);
225223
}
226224

227225
} // namespace math

stan/math/prim/functor/integrate_1d_adapter.hpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ struct integrate_1d_adapter {
1717
explicit integrate_1d_adapter(const F& f) : f_(f) {}
1818

1919
template <typename T_a, typename T_b, typename T_theta>
20-
auto operator()(const T_a& x, const T_b& xc,
21-
std::ostream *msgs,
22-
const std::vector<T_theta> &theta,
23-
const std::vector<double> &x_r,
24-
const std::vector<int> &x_i) const {
20+
auto operator()(const T_a& x, const T_b& xc, std::ostream* msgs,
21+
const std::vector<T_theta>& theta,
22+
const std::vector<double>& x_r,
23+
const std::vector<int>& x_i) const {
2524
return f_(x, xc, theta, x_r, x_i, msgs);
2625
}
2726
};

stan/math/rev/functor/integrate_1d.hpp

+51-51
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,30 @@ namespace math {
3838
*/
3939
template <typename F, typename... Args>
4040
inline double gradient_of_f(const F &f, const double &x, const double &xc,
41-
size_t n, std::ostream *msgs, const Args&... args) {
41+
size_t n, std::ostream *msgs,
42+
const Args &... args) {
4243
double gradient = 0.0;
4344

4445
// Run nested autodiff in this scope
4546
nested_rev_autodiff nested;
4647

47-
std::tuple<decltype(deep_copy_vars(args))...>
48-
args_tuple_local_copy(deep_copy_vars(args)...);
48+
std::tuple<decltype(deep_copy_vars(args))...> args_tuple_local_copy(
49+
deep_copy_vars(args)...);
4950

5051
Eigen::VectorXd adjoints = Eigen::VectorXd::Zero(count_vars(args...));
5152

52-
var fx = apply([&f, &x, &xc, msgs](auto&&... args) {
53-
return f(x, xc, msgs, args...);
54-
}, args_tuple_local_copy);
53+
var fx = apply(
54+
[&f, &x, &xc, msgs](auto &&... args) { return f(x, xc, msgs, args...); },
55+
args_tuple_local_copy);
5556

5657
fx.grad();
5758

58-
apply([&](auto&&... args) {
59-
accumulate_adjoints(adjoints.data(),
60-
std::forward<decltype(args)>(args)...);
61-
},
62-
std::move(args_tuple_local_copy));
59+
apply(
60+
[&](auto &&... args) {
61+
accumulate_adjoints(adjoints.data(),
62+
std::forward<decltype(args)>(args)...);
63+
},
64+
std::move(args_tuple_local_copy));
6365

6466
gradient = adjoints.coeff(n);
6567
if (is_nan(gradient)) {
@@ -90,13 +92,11 @@ inline double gradient_of_f(const F &f, const double &x, const double &xc,
9092
* @param args additional arguments to pass to f
9193
* @return numeric integral of function f
9294
*/
93-
template <typename F, typename T_a, typename T_b,
94-
typename... Args,
95-
require_any_st_var<T_a, T_b, Args...>* = nullptr>
95+
template <typename F, typename T_a, typename T_b, typename... Args,
96+
require_any_st_var<T_a, T_b, Args...> * = nullptr>
9697
inline return_type_t<T_a, T_b, Args...> integrate_1d_impl(
97-
const F &f, const T_a &a, const T_b &b,
98-
double relative_tolerance,
99-
std::ostream *msgs, const Args&... args) {
98+
const F &f, const T_a &a, const T_b &b, double relative_tolerance,
99+
std::ostream *msgs, const Args &... args) {
100100
static const char *function = "integrate_1d";
101101
check_less_or_equal(function, "lower limit", a, b);
102102

@@ -105,65 +105,66 @@ inline return_type_t<T_a, T_b, Args...> integrate_1d_impl(
105105

106106
if (a_val == b_val) {
107107
if (is_inf(a_val)) {
108-
throw_domain_error(function, "Integration endpoints are both",
109-
a_val, "", "");
108+
throw_domain_error(function, "Integration endpoints are both", a_val, "",
109+
"");
110110
}
111111
return var(0.0);
112112
} else {
113-
std::tuple<decltype(value_of(args))...>
114-
args_val_tuple(value_of(args)...);
113+
std::tuple<decltype(value_of(args))...> args_val_tuple(value_of(args)...);
115114

116-
double integral = integrate(apply([&f, msgs](auto&&... args) {
117-
return std::bind<double>(f, std::placeholders::_1, std::placeholders::_2,
118-
msgs, args...);
119-
}, args_val_tuple),
120-
a_val, b_val, relative_tolerance);
115+
double integral = integrate(apply(
116+
[&f, msgs](auto &&... args) {
117+
return std::bind<double>(
118+
f, std::placeholders::_1,
119+
std::placeholders::_2, msgs, args...);
120+
},
121+
args_val_tuple),
122+
a_val, b_val, relative_tolerance);
121123

122124
size_t num_vars_ab = count_vars(a, b);
123125
size_t num_vars_args = count_vars(args...);
124-
vari** varis =
125-
ChainableStack::instance_->memalloc_.alloc_array<vari*>(num_vars_ab +
126-
num_vars_args);
127-
double* partials =
128-
ChainableStack::instance_->memalloc_.alloc_array<double>(num_vars_ab +
129-
num_vars_args);
130-
double* partials_ptr = partials;
126+
vari **varis = ChainableStack::instance_->memalloc_.alloc_array<vari *>(
127+
num_vars_ab + num_vars_args);
128+
double *partials = ChainableStack::instance_->memalloc_.alloc_array<double>(
129+
num_vars_ab + num_vars_args);
130+
double *partials_ptr = partials;
131131

132132
save_varis(varis, a, b, args...);
133133

134-
for(size_t i = 0; i < num_vars_ab + num_vars_args; ++i) {
134+
for (size_t i = 0; i < num_vars_ab + num_vars_args; ++i) {
135135
partials[i] = 0.0;
136136
}
137137

138138
if (!is_inf(a) && is_var<T_a>::value) {
139-
*partials_ptr = apply([&f, a_val, msgs](auto&&... args) {
140-
return -f(a_val, 0.0, msgs, args...);
141-
}, args_val_tuple);
139+
*partials_ptr = apply(
140+
[&f, a_val, msgs](auto &&... args) {
141+
return -f(a_val, 0.0, msgs, args...);
142+
},
143+
args_val_tuple);
142144
partials_ptr++;
143145
}
144146

145147
if (!is_inf(b) && is_var<T_b>::value) {
146-
*partials_ptr = apply([&f, b_val, msgs](auto&&... args) {
147-
return f(b_val, 0.0, msgs, args...);
148-
}, args_val_tuple);
148+
*partials_ptr
149+
= apply([&f, b_val, msgs](
150+
auto &&... args) { return f(b_val, 0.0, msgs, args...); },
151+
args_val_tuple);
149152
partials_ptr++;
150153
}
151154

152155
for (size_t n = 0; n < num_vars_args; ++n) {
153156
*partials_ptr = integrate(
154-
std::bind<double>(gradient_of_f<F, Args...>, f,
155-
std::placeholders::_1, std::placeholders::_2,
156-
n, msgs, args...),
157-
a_val, b_val, relative_tolerance);
157+
std::bind<double>(gradient_of_f<F, Args...>, f, std::placeholders::_1,
158+
std::placeholders::_2, n, msgs, args...),
159+
a_val, b_val, relative_tolerance);
158160
partials_ptr++;
159161
}
160162

161-
return var(new precomputed_gradients_vari(integral,
162-
num_vars_ab + num_vars_args,
163-
varis, partials));
163+
return var(new precomputed_gradients_vari(
164+
integral, num_vars_ab + num_vars_args, varis, partials));
164165
}
165166
}
166-
167+
167168
/**
168169
* Compute the integral of the single variable function f from a to b to within
169170
* a specified relative tolerance. a and b can be finite or infinite.
@@ -225,9 +226,8 @@ inline return_type_t<T_a, T_b, T_theta> integrate_1d(
225226
const F &f, const T_a &a, const T_b &b, const std::vector<T_theta> &theta,
226227
const std::vector<double> &x_r, const std::vector<int> &x_i,
227228
std::ostream *msgs, const double relative_tolerance = std::sqrt(EPSILON)) {
228-
return integrate_1d_impl(integrate_1d_adapter<F>(f), a, b,
229-
relative_tolerance, msgs,
230-
theta, x_r, x_i);
229+
return integrate_1d_impl(integrate_1d_adapter<F>(f), a, b, relative_tolerance,
230+
msgs, theta, x_r, x_i);
231231
}
232232

233233
} // namespace math

0 commit comments

Comments
 (0)