-
Notifications
You must be signed in to change notification settings - Fork 36
Open
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:
BlockArrays.jl/src/blockindices.jl
Line 537 in cd73466
| broadcasted(::DefaultArrayStyle{1}, ::Type{<:Integer}, block_range::BlockRange{1}) = first(block_range.indices) |
which was a sloppy definition I accidentally introduced in #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"
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels