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

Don't overload * for linearindexing type computations #11579

Merged
merged 1 commit into from
Jun 6, 2015

Conversation

timholy
Copy link
Member

@timholy timholy commented Jun 4, 2015

Addresses concerns raised in 4297135#commitcomment-11513102.

This also generalizes eachindex(A, B, C...). Includes documentation and tests 😄.

end
function eachindex(A::AbstractArray, B::AbstractArray...)
@_inline_meta
eachindex(linearindexing(A,B...), A, B...)
end
eachindex(::LinearFast, A::AbstractArray, B::AbstractArray) = 1:max(length(A),length(B))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: why does this use max? Does that cause a BoundsError if the arrays are different sizes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out reducedim.jl for a fun example.

The idea is that, in cases where sizes differ, you should visit "each index," which means you should essentially traverse the bounding box. CartesianIndexes support min, so you can safely say A[min(I, Imin)] and thereby implement reductions and broadcasting.

This also generalizes `eachindex(A, B, C...)`.
@timholy timholy force-pushed the teh/linearindexing branch from 10ef7b8 to ac1cf76 Compare June 5, 2015 10:43
@JeffBezanson
Copy link
Member

LGTM! Any reason not to merge?

timholy added a commit that referenced this pull request Jun 6, 2015
Don't overload * for linearindexing type computations
@timholy timholy merged commit 6d6d05a into master Jun 6, 2015
@timholy timholy deleted the teh/linearindexing branch June 6, 2015 03:34
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

Successfully merging this pull request may close these issues.

5 participants