Skip to content

Commit cabafd6

Browse files
committed
Remove select broadcast hack
1 parent 8f5cdb8 commit cabafd6

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

stan/math/prim/prob/bernoulli_lccdf.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ 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-
// Use select() to broadcast theta values & gradients if necessary
56+
size_t theta_size = math::size(theta_arr);
57+
size_t n_size = math::size(n_arr);
58+
double broadcast_n = theta_size == n_size ? 1 : std::fmax(theta_size, n_size);
59+
5760
if (!is_constant_all<T_prob>::value) {
58-
partials<0>(ops_partials) = select(true, inv(theta_arr), n_arr);
61+
partials<0>(ops_partials) = inv(theta_arr) * broadcast_n;
5962
}
6063

61-
return ops_partials.build(sum(select(true, log(theta_arr), n_arr)));
64+
return ops_partials.build(sum(log(theta_arr)) * broadcast_n);
6265
}
6366

6467
} // namespace math

0 commit comments

Comments
 (0)