JuliaArrays / JuliaArrays/BlockArrays.jl

Broadcasting BlockRange by integer types doesn't perform proper conversions

Open Beginner friendly
#497 0 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

Broadcasting BlockRange by integer types doesn't perform proper conversions, for example:

julia> Int32.(Block(1):Block(3))
1:3

julia> eltype(Int32.(Block(1):Block(3)))
Int

This is caused by this broadcasting definition:
https://github.com/JuliaArrays/BlockArrays.jl/blob/cd73466e5e1783cf6176a0091a5838c1f2a49798/src/blockindices.jl#L537
which was a sloppy definition I accidentally introduced in https://github.com/JuliaArrays/BlockArrays.jl/pull/405 when generalizing block index types beyond Int. It could be fixed by changing that definition too:

broadcasted(::DefaultArrayStyle{1}, ::Type{T}, block_range::BlockRange{1}) where {T <: Integer} = convert(AbstractUnitRange{T}, first(block_range.indices))

Ideally we would use:

broadcasted(::DefaultArrayStyle{1}, ::Type{T}, block_range::BlockRange{1}) where {T <: Integer} = T.(first(block_range.indices))

but broadcasting unit ranges with integer types doesn't preserve unit ranges in Base right now:

julia> Int32.(1:3)
3-element Vector{Int32}:
 1
 2
 3

Version info:

julia> versioninfo()
Julia Version 1.12.4
Commit 01a2eadb047 (2026-01-06 16:56 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: macOS (arm64-apple-darwin24.0.0)
  CPU: 10 × Apple M1 Max
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, apple-m1)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 8 virtual cores)
Environment:
  JULIA_EDITOR = code

julia> pkgversion(BlockArrays)
v"1.9.3"

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

Start in src/blockindices.jl at the broadcasted definition linked in the issue, and reproduce the Int32.(Block(1):Block(3)) examples in Julia. Check that the chosen conversion preserves the expected integer element type and range behavior, then verify both the displayed result and eltype against the issue’s examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.