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
76namespace stan {
87namespace 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 */
2626template <typename T>
2727struct 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
138138template <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 */
241242template <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
0 commit comments