Skip to content

Commit f7b6c3d

Browse files
committed
clang format
1 parent 793b4f8 commit f7b6c3d

File tree

5 files changed

+309
-198
lines changed

5 files changed

+309
-198
lines changed

stan/math/fwd/functor/operands_and_partials.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ class operands_and_partials<Op1, Op2, Op3, Op4, Op5, fvar<Dx>> {
111111
template <typename EigVec, require_eigen_vector_t<EigVec>* = nullptr>
112112
auto build(EigVec&& value) {
113113
Eigen::Array<fvar<Dx>, -1, 1> ret(value.template cast<fvar<Dx>>());
114-
ret.d() = (edge1_.dx_v() + edge2_.dx_v() + edge3_.dx_v() + edge4_.dx_v() + edge5_.dx_v());
114+
ret.d() = (edge1_.dx_v() + edge2_.dx_v() + edge3_.dx_v() + edge4_.dx_v()
115+
+ edge5_.dx_v());
115116
return ret;
116117
}
117118
};
@@ -150,7 +151,6 @@ class ops_partials_edge<Dx, std::vector<fvar<Dx>>> {
150151
}
151152
return derivative;
152153
}
153-
154154
};
155155

156156
template <typename Dx, int R, int C>
@@ -215,7 +215,7 @@ class ops_partials_edge<Dx, std::vector<Eigen::Matrix<fvar<Dx>, R, C>>> {
215215
Eigen::Array<Dx, -1, 1> dx_v() {
216216
Eigen::Array<Dx, -1, 1> derivative(this->operands_.size());
217217
for (size_t i = 0; i < this->operands_.size(); ++i) {
218-
derivative[i] = this->partials_vec_[i].dot(this->operands_[i].d());
218+
derivative[i] = this->partials_vec_[i].dot(this->operands_[i].d());
219219
}
220220
return derivative;
221221
}
@@ -249,7 +249,8 @@ class ops_partials_edge<Dx, std::vector<std::vector<fvar<Dx>>>> {
249249
return derivative;
250250
}
251251
Eigen::Array<Dx, -1, 1> dx_v() {
252-
Eigen::Array<Dx, -1, 1> derivative = Eigen::Array<Dx, -1, 1>::Zero(this->operands_.size());
252+
Eigen::Array<Dx, -1, 1> derivative
253+
= Eigen::Array<Dx, -1, 1>::Zero(this->operands_.size());
253254
for (size_t i = 0; i < this->operands_.size(); ++i) {
254255
for (int j = 0; j < this->operands_[i].size(); ++j) {
255256
derivative[i] = this->partials_vec_[i][j] * this->operands_[i][j].d_;

stan/math/prim/functor/prob_reducer.hpp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#ifndef STAN_MATH_PRIM_FUNCTOR_PROB_REDUCER_HPP
22
#define STAN_MATH_PRIM_FUNCTOR_PROB_REDUCER_HPP
33

4-
54
#include <stan/math/prim/meta.hpp>
65

76
namespace stan {
87
namespace math {
98

109
/**
11-
* Used by distributions to decide whether return type shoudl be Scalar or Vector.
10+
* Used by distributions to decide whether return type shoudl be Scalar or
11+
* Vector.
1212
*/
13-
enum class ProbReturnType {Scalar, Vector};
13+
enum class ProbReturnType { Scalar, Vector };
1414

1515
/**
1616
* For scalars performs summations and is a no-op reducer for eigen vectors.
@@ -25,7 +25,7 @@ struct prob_reducer;
2525
*/
2626
template <typename T>
2727
struct prob_reducer<T, require_stan_scalar_t<T>> {
28-
T ret_; // Underlying return type
28+
T ret_; // Underlying return type
2929

3030
/**
3131
* Construct from an Eigen type
@@ -41,9 +41,11 @@ struct prob_reducer<T, require_stan_scalar_t<T>> {
4141
* @tparam Tossed An integral type
4242
* @param x will be summed and passed into `ret_`.
4343
*/
44-
template <typename EigArr, typename Tossed, require_eigen_t<EigArr>* = nullptr,
45-
require_integral_t<Tossed>* = nullptr>
46-
prob_reducer(EigArr&& x, Tossed&& /* */) : ret_(sum(std::forward<EigArr>(x))) {}
44+
template <typename EigArr, typename Tossed,
45+
require_eigen_t<EigArr>* = nullptr,
46+
require_integral_t<Tossed>* = nullptr>
47+
prob_reducer(EigArr&& x, Tossed&& /* */)
48+
: ret_(sum(std::forward<EigArr>(x))) {}
4749

4850
/**
4951
* Construct from a scalar type.
@@ -59,7 +61,8 @@ struct prob_reducer<T, require_stan_scalar_t<T>> {
5961
* @tparam Tossed an integral type
6062
* @param x will be summed and inserted into `ret_`.
6163
*/
62-
template <typename Scalar, typename Tossed, require_stan_scalar_t<Scalar>* = nullptr>
64+
template <typename Scalar, typename Tossed,
65+
require_stan_scalar_t<Scalar>* = nullptr>
6366
prob_reducer(Scalar&& x, Tossed&& /* */) : ret_(x) {}
6467

6568
/**
@@ -119,9 +122,7 @@ struct prob_reducer<T, require_stan_scalar_t<T>> {
119122
/**
120123
* Return the underlying scalar return type.
121124
*/
122-
inline auto ret() noexcept {
123-
return ret_;
124-
}
125+
inline auto ret() noexcept { return ret_; }
125126

126127
/**
127128
* Return a zero value, used when distribution has special cases that
@@ -132,7 +133,6 @@ struct prob_reducer<T, require_stan_scalar_t<T>> {
132133
static auto zero(int /* */) {
133134
return return_type_t<Types...>(0);
134135
}
135-
136136
};
137137

138138
template <typename T>
@@ -153,7 +153,8 @@ struct prob_reducer<T, require_eigen_t<T>> {
153153
* @tparam Tossed An integral type
154154
* @param x will be forwarded to `ret_`.
155155
*/
156-
template <typename EigArr, typename Size, require_eigen_t<EigArr>* = nullptr, require_integral_t<Size>* = nullptr>
156+
template <typename EigArr, typename Size, require_eigen_t<EigArr>* = nullptr,
157+
require_integral_t<Size>* = nullptr>
157158
prob_reducer(EigArr&& x, Size /* x */) : ret_(std::forward<EigArr>(x)) {}
158159

159160
/**
@@ -163,8 +164,9 @@ struct prob_reducer<T, require_eigen_t<T>> {
163164
* @param x passed to `ret_` along with size to fill with a base value.
164165
* @param n The size `ret_` should be
165166
*/
166-
template <typename Scalar, typename Size, require_stan_scalar_t<Scalar>* = nullptr,
167-
require_integral_t<Size>* = nullptr>
167+
template <typename Scalar, typename Size,
168+
require_stan_scalar_t<Scalar>* = nullptr,
169+
require_integral_t<Size>* = nullptr>
168170
prob_reducer(Scalar constant, Size n) : ret_(T::Constant(n, constant)) {}
169171

170172
/**
@@ -216,9 +218,7 @@ struct prob_reducer<T, require_eigen_t<T>> {
216218
* Return the underlying scalar return type. Passed the underlying by
217219
* moving it which can cause `ret_` to be uninitialized after.
218220
*/
219-
inline auto&& ret() noexcept {
220-
return std::move(ret_);
221-
}
221+
inline auto&& ret() noexcept { return std::move(ret_); }
222222

223223
/**
224224
* Return a zero value, used when distribution has special cases that
@@ -228,20 +228,23 @@ struct prob_reducer<T, require_eigen_t<T>> {
228228
*/
229229
template <typename... Types>
230230
static auto zero(int size) {
231-
return Eigen::Array<return_type_t<Types...>, -1, 1>::Constant(0, size).eval();
231+
return Eigen::Array<return_type_t<Types...>, -1, 1>::Constant(0, size)
232+
.eval();
232233
}
233-
234234
};
235235

236236
/**
237237
* Generate a reducer with correct return type.
238238
* @tparam ReturnType Either Scalar or Vector.
239-
* @tparam Types A parameter pack of types to deduce the underlying scalar type from
239+
* @tparam Types A parameter pack of types to deduce the underlying scalar type
240+
* from
240241
*/
241242
template <ProbReturnType ReturnType, typename... Types>
242-
using prob_return_t = prob_reducer<std::conditional_t<ReturnType == ProbReturnType::Scalar, return_type_t<Types...>, Eigen::Array<return_type_t<Types...>, -1, 1>>>;
243+
using prob_return_t = prob_reducer<std::conditional_t<
244+
ReturnType == ProbReturnType::Scalar, return_type_t<Types...>,
245+
Eigen::Array<return_type_t<Types...>, -1, 1>>>;
243246

244-
}
245-
}
247+
} // namespace math
248+
} // namespace stan
246249

247250
#endif

stan/math/prim/prob/normal_lpdf.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ namespace math {
3939
* @return The log of the product of the densities.
4040
* @throw std::domain_error if the scale is not positive.
4141
*/
42-
template <bool propto, ProbReturnType RetType = ProbReturnType::Scalar, typename T_y, typename T_loc, typename T_scale,
42+
template <bool propto, ProbReturnType RetType = ProbReturnType::Scalar,
43+
typename T_y, typename T_loc, typename T_scale,
4344
require_all_not_nonscalar_prim_or_rev_kernel_expression_t<
4445
T_y, T_loc, T_scale>* = nullptr>
45-
inline auto normal_lpdf(const T_y& y,
46-
const T_loc& mu,
47-
const T_scale& sigma) {
46+
inline auto normal_lpdf(const T_y& y, const T_loc& mu, const T_scale& sigma) {
4847
using T_partials_return = partials_return_t<T_y, T_loc, T_scale>;
4948
using T_y_ref = ref_type_if_t<!is_constant<T_y>::value, T_y>;
5049
using T_mu_ref = ref_type_if_t<!is_constant<T_loc>::value, T_loc>;
@@ -116,9 +115,7 @@ inline auto normal_lpdf(const T_y& y,
116115
}
117116

118117
template <typename T_y, typename T_loc, typename T_scale>
119-
inline auto normal_lpdf(const T_y& y,
120-
const T_loc& mu,
121-
const T_scale& sigma) {
118+
inline auto normal_lpdf(const T_y& y, const T_loc& mu, const T_scale& sigma) {
122119
return normal_lpdf<false>(y, mu, sigma);
123120
}
124121

test/unit/math/mix/prob/normal_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ TEST(mathMixScalFun, normal_lpdf) {
1313

1414
TEST(mathMixScalFun, vnormal_lpdf) {
1515
auto f = [](const auto& y, const auto& mu, const auto& sigma) {
16-
return stan::math::normal_lpdf<true, stan::math::ProbReturnType::Vector>(y, mu, sigma);
16+
return stan::math::normal_lpdf<true, stan::math::ProbReturnType::Vector>(
17+
y, mu, sigma);
1718
};
1819
Eigen::VectorXd y = Eigen::VectorXd::Random(5);
19-
//y << 0, 0;
20+
// y << 0, 0;
2021
Eigen::VectorXd mu = Eigen::VectorXd::Random(5);
21-
//mu << 0, 0;
22+
// mu << 0, 0;
2223
Eigen::VectorXd sigma = stan::math::abs(Eigen::VectorXd::Random(5));
23-
//sigma << 1, 1;
24+
// sigma << 1, 1;
2425
stan::test::expect_ad_distribution(f, y, mu, sigma);
25-
//stan::test::expect_ad(f, y, mu, sigma);
26-
26+
// stan::test::expect_ad(f, y, mu, sigma);
2727
}

0 commit comments

Comments
 (0)