Skip to content

Drop implicit broadcasting of observations #919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mhauru opened this issue May 14, 2025 · 2 comments
Open

Drop implicit broadcasting of observations #919

mhauru opened this issue May 14, 2025 · 2 comments

Comments

@mhauru
Copy link
Member

mhauru commented May 14, 2025

We currently allow this:

julia> @model function f(vector, matrix)
           mean ~ Normal()
           vector ~ Normal(mean)
           matrix ~ MvNormal(fill(mean, 2), I)
           return nothing
       end

julia> f([1.0, 2.0], [1.0 2.0 3.0; 4.0 5.0 6.0])

In other words, we implicitly broadcast ~ statements when the RHS is of lesser tensor rank (scalar, vector, matrix, etc.) than the LHS. We only do this for observations, for assumptions we require the use of .~ for univariate distributions or loops for multivariate ones.

Are we sure we want to keep supporting this long-term? I find it confusing for the same reasons I described in #825 (comment), namely that it muddies the distinction between distributions of different tensor rank and goes against Julia's broadcasting conventions, such as disallowing things like [0.1, 0.2] + 1.0. Also, the univariate cases can trivially be changed to use .~ instead. The multivariate cases would require loops.

This issue is kinda the mirror image of #825. This arose originally from a question of why does tilde_observe call loglikelihood when tilde_assume calls logpdf here.

@penelopeysm
Copy link
Member

Strong vote for removing it.

@yebai
Copy link
Member

yebai commented May 15, 2025

Happy to remove it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants