-
Notifications
You must be signed in to change notification settings - Fork 31
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
Broadcast.broadcast_shape
for BlockedUnitRanges fails inference
#310
Comments
Broadcast.broadcast_shape
for BlockedUnitRanges fail inference
Broadcast.broadcast_shape
for BlockedUnitRanges fail inferenceBroadcast.broadcast_shape
for BlockedUnitRanges fails inference
This comes from BlockArrays.jl/src/blockbroadcast.jl Line 37 in ec8c7f5
Perhaps we may remove the special-casing, as the performance impact in the 1-term union will be minimal |
Yeah, I tried fixing this. I'll open the PR for convenience (#312). First, I thought that the core issue was that julia> union((1,), (2,))
2-element Vector{Int64}:
1
2 However, even after fixing that in the PR (which borrows some functions in TupleTools.jl and defines So, while this could fix the type preservation, it won't actually fix the type instability. If you have ideas about how to make |
I think it's better for this to return a vector, as the non-trivial branch does. Since |
Yeah, that does fix it. I guess it's worth it. The general case of calling |
I'll update the PR |
Ok, the PR is updated. |
Thanks for the tip @jishnub! |
Actually, I prefer #313 if that's okay 🙂 |
So, it seems that I updated #313, and basically specialized it so that the tests pass, but I have a feeling that I'm introducing inconsistent behavior between I think one potential solution would be to put the struct BlockedUnitRange{CS,L} <: AbstractUnitRange{Int}
first::Int
lasts::CS
global _BlockedUnitRange(f, cs::CS) where CS = new{CS, len(f, cs)}(f, cs)
end
len(f, l) = isempty(l) ? 0 : Integer(last(l)-f+1)
...
length(a::BlockedUnitRange{CS, L}) where {CS, L} = L which will make the call to Thoughts? jishnub |
I wonder if a simple workaround might be to convert the return value of |
Absolutely not: one of the usages downstream are infinite dimensional block array, and even without that we want to support allocation-free axes when the block sizes are Note this really is an issue inherited with Base's broadcasting: they never should have supported degenerate sizes like We could potentially disallow degenerate broadcasting for blocked arrays. We'd have to see what tests fail downstream. |
Agreed, the main reason for fixing this issue is to avoid allocations. So ideally we have a solution that is fully inferred and stack allocated. |
MWE:
The text was updated successfully, but these errors were encountered: