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

Inline blocksizes for better type-inference #429

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Nov 7, 2024

Fixes #425

The type-inference should work within a function now, as the dimension will be propagated to axes as a constant:

julia> using BlockArrays, Test

julia> x = BlockedArray(rand(4, 4), [2, 2], [2, 2]);

julia> @inferred (x -> blocksizes(x, 1))(x)
2-element Vector{Int64}:
 2
 2

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.55%. Comparing base (a62bd8e) to head (1d2c7d0).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #429   +/-   ##
=======================================
  Coverage   93.55%   93.55%           
=======================================
  Files          18       18           
  Lines        1644     1644           
=======================================
  Hits         1538     1538           
  Misses        106      106           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lkdvos
Copy link

lkdvos commented Nov 9, 2024

I can confirm that this resolved the type-instability in #426 , thank you!

As a small comment, that I rejected myself after going through the actual implications, but might want to leave here for future reference.

As an additional suggestion, this might also not be unreasonable, and further improve the type-stability in the case of block arrays with BlockedOneTo axes:

Currently, the combination of this definition and this definition imply that the following things don't coincide:

a = rand(3)
blockaxes(a, 1) # BlockRange(Base.OneTo(1))
blockaxes(a, 2) # Base.OneTo(1)
blockaxes(axes(a, 2), 1) # BlockRange(Base.OneTo(1))

To me it seems like the latter is a much more reasonable fallback for "trailing indexes", and this would resolve the type-instability for the typical BlockArray cases.

This suggestion does not really work because I didn't fully realize that a[Block(1), 1] and a[Block(1), Block(1)] do not actually mean the same thing (the former is a vector, the latter a matrix).

@jishnub jishnub force-pushed the jishnub/blocksizeconstprop branch from eb95d65 to 1d2c7d0 Compare December 3, 2024 08:04
@jishnub jishnub merged commit def5e59 into master Dec 3, 2024
16 checks passed
@jishnub jishnub deleted the jishnub/blocksizeconstprop branch December 3, 2024 09:06
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.

Type instability of blocksizes(y, i)
2 participants