Skip to content
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

Fix Broadcast.broadcast_shape inference #313

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

charleskawczynski
Copy link

@charleskawczynski charleskawczynski commented Sep 21, 2023

This is an alternative to #312.

I noticed that, in the case when the union combines both entries, the result should still be correct (that's what the existing code is doing afterall). If we make tuples always combine entries then we have the benefit of Base.Broadcast.broadcast_shape both being stack allocated and fully type inferred. This fixes my upstream issue (and I would prefer this solution over #312).

@jishnub, does this look okay?

Closes #310.

@codecov
Copy link

codecov bot commented Sep 22, 2023

Codecov Report

Merging #313 (549a1e1) into master (cf7c29c) will increase coverage by 92.48%.
Report is 4 commits behind head on master.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           master     #313       +/-   ##
===========================================
+ Coverage    0.00%   92.48%   +92.48%     
===========================================
  Files          16       16               
  Lines        1469     1491       +22     
===========================================
+ Hits            0     1379     +1379     
+ Misses       1469      112     -1357     
Files Coverage Δ
src/blockbroadcast.jl 92.91% <100.00%> (+92.91%) ⬆️

... and 15 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@jishnub
Copy link
Member

jishnub commented Sep 22, 2023

This appears to be breaking. Could you look into the failing tests?

@charleskawczynski
Copy link
Author

This appears to be breaking. Could you look into the failing tests?

Ah, sorry, I didn't realize there were downstream tests, I only checked the unit tests locally. How can I run the downstream tests? It looks like I need to clone the downstream and dev this branch?

@jishnub
Copy link
Member

jishnub commented Sep 22, 2023

Yes, that's the way

@dlfivefifty
Copy link
Member

I guess this is only inferrable for vector broadcasting? I think that's fine

@charleskawczynski
Copy link
Author

I guess this is only inferrable for vector broadcasting? I think that's fine

It's not clear to me that vector broadcasting is the only thing impacted, but I'm not super familiar with this package's internals. This is only overloading cases when BlockedUnitRange's last entries are Tuples, so that it's stack-allocated / fully inferred. The tests that are added in this PR fail on the master branch (see #310).

@@ -30,13 +30,16 @@ BroadcastStyle(::PseudoBlockStyle{M}, ::BlockStyle{N}) where {M,N} = BlockStyle(

# sortedunion can assume inputs are already sorted so this could be improved
sortedunion(a,b) = sort!(union(a,b))
sortedunion_tuple(a::Tuple, b::Tuple) = (a..., b...)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this not really a union since it doesn't remove elements that a and b might have in common?

Could call it disjointsortedunion_tuple or something like that to clarify the inputs should also be disjoint.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Also, I'm not sure how I can fix the issues that come from this change..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only "solution" might be to somehow avoid this codepath, which I've not had enough time to try

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

Successfully merging this pull request may close these issues.

Broadcast.broadcast_shape for BlockedUnitRanges fails inference
4 participants