BlockArrays.jl icon indicating copy to clipboard operation
BlockArrays.jl copied to clipboard

Linear indexing into block arrays

Open daanhb opened this issue 4 years ago • 3 comments

This issue relates to #168, where linear indices in a BlockIndex led to a stack overflow.

A question that arises is whether linear indexing should be supported and if so, how. Currently, there is this behaviour:

julia> using BlockArrays
A = [1 2; 3 4]
julia> A = [1 2; 3 4]
2×2 Array{Int64,2}:
 1  2
 3  4

julia> A[Block(1,1)]
2×2 Array{Int64,2}:
 1  2
 3  4

julia> A[Block(1)]
2-element Array{Int64,1}:
 1
 3

julia> A[Block(2)]
ERROR: BlockBoundsError: attempt to access 2-element Base.OneTo{Int64} at block index [2]

Indexing a matrix with Block(1) yields the first column only, but Block(2) does not yield the second column. The blocksize of the matrix is 1 indicating that A[Block(1)] == A may be more consistent. But that would be an incompatible change.

daanhb avatar Mar 24 '21 08:03 daanhb

You are right, I consider that to be a bug (bug fixes are not breaking)

dlfivefifty avatar Mar 24 '21 08:03 dlfivefifty

Okay, I'll try to look into it, if it doesn't become too comprehensive. I'm not very familiar with BlockArrays.jl yet, though for another package the functionality is just what I need.

daanhb avatar Mar 24 '21 08:03 daanhb

That was doable, I updated the pull request #168.

daanhb avatar Mar 24 '21 09:03 daanhb