-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
collect doesn't preserve shape on Broadcased
objects
#43847
Comments
You forgot julia> h = Base.broadcasted(sqrt, [1 2; 3 4])
Base.Broadcast.Broadcasted(sqrt, ([1 2; 3 4],))
julia> h2 = Broadcast.instantiate(h)
Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{2}}(sqrt, ([1 2; 3 4],))
julia> collect(h2)
2×2 Matrix{Float64}:
1.0 1.41421
1.73205 2.0 |
How so? Without instantiate it still defines |
Agreed. In particular, |
I am not sure if we can replace it, because it might be being hit by something that is otherwise overloading the broadcast style in a package. |
consider a 2D generator
All is well.
But for a
Broadcasted
object the shape is not preserved andcollect
gives back something flat.This can be fixed by
materializing
firstBut why does it not work in the first place.
I suspect it is because the
IteratorSize
trait isn't set toHasShape
.But why isn't it?
It seems to just be hitting the default fallback defintion of
IteratorSize
rather than:
julia/base/broadcast.jl
Line 264 in 591f066
We do have:
And that
Base.Broadcast.DefaultArrayStyle{2}
tells us what we need to know to define theHasShape
It seems like we could define
and indeed that does seem to work
The text was updated successfully, but these errors were encountered: