Skip to content

Commit

Permalink
Reduce unnecessary computation
Browse files Browse the repository at this point in the history
  • Loading branch information
andrjohns committed Aug 11, 2023
1 parent bd11e54 commit 8f5cdb8
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions stan/math/prim/prob/bernoulli_lccdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ return_type_t<T_prob> bernoulli_lccdf(const T_n& n, const T_prob& theta) {
return ops_partials.build(NEGATIVE_INFTY);
}

const auto& theta_broadcast = select(true, theta_arr, n_arr);

// Use select() to broadcast theta values & gradients if necessary
if (!is_constant_all<T_prob>::value) {
partials<0>(ops_partials) = inv(theta_broadcast);
partials<0>(ops_partials) = select(true, inv(theta_arr), n_arr);
}

return ops_partials.build(sum(log(theta_broadcast)));
return ops_partials.build(sum(select(true, log(theta_arr), n_arr)));
}

} // namespace math
Expand Down

0 comments on commit 8f5cdb8

Please sign in to comment.