Skip to content

Multi-argument eachindex #10906

@lindahua

Description

@lindahua

The eachindex is a great function, which provides a uniform & efficient way to traverse a array.

However, in many cases, the computation require multiple arguments, e.g., addition.

s = rand(5, 6)
a = rand(4, 6)   # with fast linear indexing
b = sub(s, 1:4, :)   # no fast linear indexing
c = zeros(4, 6)

# It would be great to do the following
for (ia, ib, ic) in eachindex(a, b, c)
    c[ic] = a[ia] + b[ib]
end

A more greedy demand is to allow broadcasting eachindex when arrays have different sizes, but their shapes are compatible (in terms of broadcasting).

cc: @timholy

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions