Skip to content

Type instability of blocksizes(y, i) #425

Closed
@lkdvos

Description

@lkdvos

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions