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

Type instability of blocksizes(y, i) #425

Closed
lkdvos opened this issue Oct 31, 2024 · 1 comment · Fixed by #429
Closed

Type instability of blocksizes(y, i) #425

lkdvos opened this issue Oct 31, 2024 · 1 comment · Fixed by #429

Comments

@lkdvos
Copy link

lkdvos commented Oct 31, 2024

I'm running into a subtle type-instability with blocksizes, which breaks the type-inference of a function I am trying to define further down the line.

using BlockArrays
x = BlockedArray(rand(4, 4), [2, 2], [2, 2])

@inferred blocksizes(x, 1)
ERROR: return type Vector{Int64} does not match inferred return type Union{FillArrays.Fill{Int64, 1, Tuple{Base.OneTo{Int64}}}, Vector{Int64}}

I did some digging, and it seems that the culprit is that Base.axes(::AbstractArray, n) will output a OneTo whenever n is larger than the number of dimensions. It seems like the compiler isn't able to const-propagate the n to figure this out. I was wondering if there is a way to avoid this instability, maybe by defining a fallback for axes(::AbstractBlockArray, d::Int) to output a BlockedOneTo instead?

I can definitely open a PR to make changes and tests, I just wanted to ask for some comments and feedback first.

@jishnub
Copy link
Member

jishnub commented Nov 7, 2024

This should be fixed by #429, but this would work only within a function, and not at the top-level. This is because the dimension needs to be constant-propagated, and such optimizations won't happen at the top level.

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 a pull request may close this issue.

2 participants