JuliaArrays / JuliaArrays/BlockArrays.jl
Potential issue with `findblock[index]` for `BlockUnitRange` with `first != 1`
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 254
- Forks
- 39
- PR merge metrics
- No merged PRs in 30d
Description
Perhaps I am misunderstanding how findblock[index] is supposed to work, but this behavior is confusing to me:
julia> using BlockArrays
julia> r = BlockArrays._BlockedUnitRange(2, [4, 6])
2-blocked 5-element BlockedUnitRange{Vector{Int64}}:
2
3
4
─
5
6
julia> findblock(r, 1)
ERROR: BoundsError: attempt to access 2-blocked 5-element BlockedUnitRange{Vector{Int64}} at index [1]
Stacktrace:
[1] findblock(b::BlockedUnitRange{Vector{Int64}}, k::Int64)
@ BlockArrays ~/.julia/packages/BlockArrays/L5yjb/src/blockaxis.jl:299
[2] top-level scope
@ REPL[27]:1
julia> findblock(r, 2)
Block(1)
julia> findblock(r, 3)
Block(1)
julia> findblock(r, 4)
Block(1)
julia> findblock(r, 5)
Block(2)
I expected it to return:
julia> findblock(r, 1)
Block(1)
julia> findblock(r, 2)
Block(1)
julia> findblock(r, 3)
Block(1)
julia> findblock(r, 4)
Block(2)
julia> findblock(r, 5)
Block(2)
i.e. in a call to findblock(r, k), I was interpreting k as an index, and thought findblock would output the block that index is in, but it seems to be interpreting k as a value, and is outputting the block that value is in.
Maybe the giveaway is that find* functions in Base find the index of a value, so the current behavior of findblock is consistent with that convention, and really I was just hoping for a different function with a different functionality.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the examples with BlockArrays._BlockedUnitRange and inspect findblock in src/blockaxis.jl around line 299. Determine whether the API should distinguish value-based and index-based lookup, then review any nearby tests or documentation before proposing the intended behavior; completion requires an explicit, tested convention or a separate index-based operation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100