Skip to content

Broadcasted addition of one CarteseanIndex to an array of them emits cryptic error #41540

@BioTurboNick

Description

@BioTurboNick
julia> a = CartesianIndex(1, 2, 3)

julia> b = [a, a, a]
3-element Vector{CartesianIndex{3}}:
 CartesianIndex(1, 2, 3)
 CartesianIndex(1, 2, 3)
 CartesianIndex(1, 2, 3)

julia> b .+ a
ERROR: iteration is deliberately unsupported for CartesianIndex. Use `I` rather than `I...`, or use `Tuple(I)...`

# works
julia> b .+ Ref(a)
3-element Vector{CartesianIndex{3}}:
 CartesianIndex(2, 4, 6)
 CartesianIndex(2, 4, 6)
 CartesianIndex(2, 4, 6)

# works
julia> [c + a for c in b]
3-element Vector{CartesianIndex{3}}:
 CartesianIndex(2, 4, 6)
 CartesianIndex(2, 4, 6)
 CartesianIndex(2, 4, 6)

If iteration across the values of CarteseanIndex is not supported, shouldn't it just treat it as an atomic value in the broadcast without the need to wrap it in Ref()?

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions