JuliaArrays / BlockArrays.jl

BlockArrays for Julia
http://juliaarrays.github.io/BlockArrays.jl/
Other
199 stars 29 forks source link

`a[Block()[]]` when `iszero(ndims(a))` returns a block, not an element #430

Closed mtfishman closed 4 hours ago

mtfishman commented 2 weeks ago

For example:

julia> using BlockArrays

julia> a = BlockArray{Float64}(undef)
-blocked 0-dimensional BlockArray{Float64, 0}:
1.04e-322

julia> a[] = 2
2

julia> a
-blocked 0-dimensional BlockArray{Float64, 0}:
2.0

julia> a[Block()]
0-dimensional Array{Float64, 0}:
2.0

julia> a[Block()][]
2.0

julia> a[Block()[]]
0-dimensional Array{Float64, 0}:
2.0

julia> pkgversion(BlockArrays)
v"1.1.1"
mtfishman commented 2 weeks ago

I see, the issue stems from:

julia> Block()[]
Block()

julia> Block()[CartesianIndex()]
Block()

which is defined here: https://github.com/JuliaArrays/BlockArrays.jl/blob/v1.1.1/src/blockindices.jl#L205 and here: https://github.com/JuliaArrays/BlockArrays.jl/blob/v1.1.1/src/blockindices.jl#L59. I assume that should output BlockIndex() (which isn't defined yet, but could be defined as BlockIndex{0,Tuple{},Tuple{}}((), ())).