JuliaArrays / JuliaArrays/BlockArrays.jl

Handle empty blocks upon `mortar`

Open
#203 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
254
Forks
39
PR merge metrics
No merged PRs in 30d

Description

I just ran into the following behavior (due to another bug in my own code):

julia> a = mortar([Bool[], Bool[], [true, false]])
julia> a .|| a
ERROR: BoundsError: attempt to access 0-element UnitRange{Int64} at index [1:2]
Full Stacktrace
Stacktrace:
  [1] throw_boundserror(A::UnitRange{Int64}, I::Tuple{UnitRange{Int64}})
    @ Base ./abstractarray.jl:691
  [2] checkbounds
    @ ./abstractarray.jl:656 [inlined]
  [3] getindex
    @ ./range.jl:918 [inlined]
  [4] getindex
    @ ~/.julia/packages/BlockArrays/tr499/src/blockaxis.jl:10 [inlined]
  [5] unblock
    @ ~/.julia/packages/BlockArrays/tr499/src/views.jl:10 [inlined]
  [6] to_indices
    @ ~/.julia/packages/BlockArrays/tr499/src/views.jl:28 [inlined]
  [7] to_indices
    @ ~/.julia/packages/BlockArrays/tr499/src/views.jl:43 [inlined]
  [8] view(A::BlockVector{Bool, Vector{Vector{Bool}}, Tuple{BlockedUnitRange{Vector{Int64}}}}, I::BlockArrays.BlockIndexRange{1, Tuple{UnitRange{Int64}}})
    @ Base ./subarray.jl:176
  [9] _bview
    @ ~/.julia/packages/BlockArrays/tr499/src/blockbroadcast.jl:145 [inlined]
 [10] macro expansion
    @ ~/.julia/packages/BlockArrays/tr499/src/blockbroadcast.jl:175 [inlined]
 [11] _generic_blockbroadcast_copyto!(dest::BlockVector{Bool, Vector{Vector{Bool}}, Tuple{BlockedUnitRange{Vector{Int64}}}}, bc::Base.Broadcast.Broadcasted{BlockArrays.BlockStyle{1}, Tuple{BlockedUnitRange{Vector{Int64}}}, Base.Broadcast.var"#5#6", Tuple{BlockVector{Bool, Vector{Vector{Bool}}, Tuple{BlockedUnitRange{Vector{Int64}}}}, BlockVector{Bool, Vector{Vector{Bool}}, Tuple{BlockedUnitRange{Vector{Int64}}}}}})
    @ BlockArrays ~/.julia/packages/BlockArrays/tr499/src/blockbroadcast.jl:151
 [12] copyto!(dest::BlockVector{Bool, Vector{Vector{Bool}}, Tuple{BlockedUnitRange{Vector{Int64}}}}, bc::Base.Broadcast.Broadcasted{BlockArrays.BlockStyle{1}, Tuple{BlockedUnitRange{Vector{Int64}}}, Base.Broadcast.var"#5#6", Tuple{BlockVector{Bool, Vector{Vector{Bool}}, Tuple{BlockedUnitRange{Vector{Int64}}}}, BlockVector{Bool, Vector{Vector{Bool}}, Tuple{BlockedUnitRange{Vector{Int64}}}}}})
    @ BlockArrays ~/.julia/packages/BlockArrays/tr499/src/blockbroadcast.jl:219
 [13] copy
    @ ./broadcast.jl:885 [inlined]
 [14] materialize(bc::Base.Broadcast.Broadcasted{BlockArrays.BlockStyle{1}, Nothing, Base.Broadcast.var"#5#6", Tuple{BlockVector{Bool, Vector{Vector{Bool}}, Tuple{BlockedUnitRange{Vector{Int64}}}}, BlockVector{Bool, Vector{Vector{Bool}}, Tuple{BlockedUnitRange{Vector{Int64}}}}}})
    @ Base.Broadcast ./broadcast.jl:860
 [15] top-level scope
    @ REPL[137]:1
 [16] top-level scope
    @ ~/.julia/packages/Infiltrator/WQe1n/src/Infiltrator.jl:508
 [17] top-level scope

It was surprisingly annoying to find where this was coming from since the faulty a::BlockVector{Bool} in many ways behaves normally but broadcasting then fails. It may be a good idea to just throw an error upon mortar with empty blocks or eliminate them silently (though that may cause other surprises, and, in my case, would have hidden the actual error that I had).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example in the Julia REPL, then trace the failure through src/blockaxis.jl, src/views.jl, and src/blockbroadcast.jl as shown in the stacktrace. Determine and document the intended behavior for empty blocks—rejecting them or removing them—and ensure broadcasting a mortared vector no longer raises this BoundsError.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.