Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-argument eachindex #10906

Closed
lindahua opened this issue Apr 20, 2015 · 2 comments
Closed

Multi-argument eachindex #10906

lindahua opened this issue Apr 20, 2015 · 2 comments

Comments

@lindahua
Copy link
Contributor

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

@timholy
Copy link
Member

timholy commented Apr 20, 2015

Agreed on both points. The two-argument version was just implemented in #10858, but I agree we could probably use a multi-argument version. For the broadcasting idea, there's something like that in reducedim, but I think it only adds trailing 1s. You can use max(I1,I2) on two CartesianIndexes. I bet all this is not as flexible or easy to use as it should be, however.

@tkelman
Copy link
Contributor

tkelman commented Jan 5, 2017

doesn't seem release-blocking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants