diff --git a/stan/math/prim/fun/grad_pFq.hpp b/stan/math/prim/fun/grad_pFq.hpp index 11feaa9b0ac..77040ea849e 100644 --- a/stan/math/prim/fun/grad_pFq.hpp +++ b/stan/math/prim/fun/grad_pFq.hpp @@ -111,8 +111,8 @@ auto grad_pFq(const TpFq& pfq_val, const Ta& a, const Tb& b, const Tz& z, std::tuple>, promote_scalar_t>, T_Rtn> ret_tuple; - std::get<0>(ret_tuple).setConstant(a.size(), 0.0); - std::get<1>(ret_tuple).setConstant(b.size(), 0.0); + std::get<0>(ret_tuple).setConstant(a.size(), -pfq_val); + std::get<1>(ret_tuple).setConstant(b.size(), pfq_val); std::get<2>(ret_tuple) = 0.0; if (CalcA || CalcB) { @@ -152,13 +152,6 @@ auto grad_pFq(const TpFq& pfq_val, const Ta& a, const Tb& b, const Tz& z, b_k += 1.0; k += 1; } - - if (CalcA) { - std::get<0>(ret_tuple).array() -= pfq_val; - } - if (CalcB) { - std::get<1>(ret_tuple).array() += pfq_val; - } } if (CalcZ) { T_Rtn pfq_p1_val