While I can broadcast scalars, like
julia> 1 .+ (2, 3)
(3, 4)
I can’t do the same with CartesianIndex
s:
julia> CartesianIndex(1,1) .+ (CartesianIndex(2,2), CartesianIndex(3,3))
ERROR: iteration is deliberately unsupported for CartesianIndex. Use `I` rather than `I...`, or use `Tuple(I)...`
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] iterate(::CartesianIndex{2}) at ./multidimensional.jl:166
[3] copyto!(::Array{Int64,1}, ::CartesianIndex{2}) at ./abstractarray.jl:733
[4] _collect(::UnitRange{Int64}, ::CartesianIndex{2}, ::Base.HasEltype, ::Base.HasLength) at ./array.jl:630
[5] collect(::CartesianIndex{2}) at ./array.jl:624
[6] broadcastable(::CartesianIndex{2}) at ./broadcast.jl:682
[7] broadcasted(::Function, ::CartesianIndex{2}, ::Tuple{CartesianIndex{2},CartesianIndex{2}}) at ./broadcast.jl:1260
[8] top-level scope at REPL[15]:1
I understand that 1 .+ CartesianIndex(1,1)
fails, but since CartesianIndex(1,1) + CartesianIndex(1,1)
is fine, I would expect the above example to work. Is the behavior intended, or a bug?
(I can of course write
julia> (CartesianIndex(1,1),) .+ (CartesianIndex(2,2), CartesianIndex(3,3))
(CartesianIndex(3, 3), CartesianIndex(4, 4))
instead. But that’s less elegant… and beside the point.)