Skip to content

Commit 8f5cdb8

Browse files
committed
Reduce unnecessary computation
1 parent bd11e54 commit 8f5cdb8

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

stan/math/prim/prob/bernoulli_lccdf.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@ return_type_t<T_prob> bernoulli_lccdf(const T_n& n, const T_prob& theta) {
5353
return ops_partials.build(NEGATIVE_INFTY);
5454
}
5555

56-
const auto& theta_broadcast = select(true, theta_arr, n_arr);
57-
56+
// Use select() to broadcast theta values & gradients if necessary
5857
if (!is_constant_all<T_prob>::value) {
59-
partials<0>(ops_partials) = inv(theta_broadcast);
58+
partials<0>(ops_partials) = select(true, inv(theta_arr), n_arr);
6059
}
6160

62-
return ops_partials.build(sum(log(theta_broadcast)));
61+
return ops_partials.build(sum(select(true, log(theta_arr), n_arr)));
6362
}
6463

6564
} // namespace math

0 commit comments

Comments
 (0)