1212#include < stan/math/prim/fun/sum.hpp>
1313#include < stan/math/prim/fun/sign.hpp>
1414#include < stan/math/prim/fun/value_of_rec.hpp>
15- #include < stan/math/prim/fun/log_sum_exp_signed.hpp>
1615
1716namespace stan {
1817namespace math {
@@ -31,7 +30,7 @@ T_return hypergeometric_3F2_infsum(const Ta& a, const Tb& b, const Tz& z,
3130 check_3F2_converges (" hypergeometric_3F2" , a_array[0 ], a_array[1 ], a_array[2 ],
3231 b_array[0 ], b_array[1 ], z);
3332
34- T_return t_acc = 0 .0 ;
33+ T_return t_acc = 1 .0 ;
3534 T_return log_t = 0.0 ;
3635 T_return log_z = log (fabs (z));
3736 Eigen::ArrayXi a_signs = sign (value_of_rec (a_array));
@@ -40,7 +39,7 @@ T_return hypergeometric_3F2_infsum(const Ta& a, const Tb& b, const Tz& z,
4039 plain_type_t <decltype (b_array)> bpk = b_array;
4140 int z_sign = sign (value_of_rec (z));
4241 int t_sign = z_sign * a_signs.prod () * b_signs.prod ();
43- int acc_sign = 1 ;
42+
4443 int k = 0 ;
4544 while (k <= max_steps && log_t >= log (precision)) {
4645 // Replace zero values with 1 prior to taking the log so that we accumulate
@@ -53,8 +52,7 @@ T_return hypergeometric_3F2_infsum(const Ta& a, const Tb& b, const Tz& z,
5352 }
5453
5554 log_t += p + log_z;
56- std::forward_as_tuple (t_acc, acc_sign)
57- = log_sum_exp_signed (t_acc, acc_sign, log_t , t_sign);
55+ t_acc += t_sign * exp (log_t );
5856
5957 if (is_inf (t_acc)) {
6058 throw_domain_error (" hypergeometric_3F2" , " sum (output)" , t_acc,
@@ -72,7 +70,7 @@ T_return hypergeometric_3F2_infsum(const Ta& a, const Tb& b, const Tz& z,
7270 " exceeded iterations, hypergeometric function did not " ,
7371 " converge." );
7472 }
75- return acc_sign * exp ( t_acc) ;
73+ return t_acc;
7674}
7775} // namespace internal
7876
0 commit comments