-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Change for i=1:length(A)
to for i in eachindex(A)
#10858
Conversation
This sounds like it should be a mailing list post, and an addition to the MATLAB differences list (not sure what other languages this is relevant for)? Should use of |
+1 A benchmark that shows the speed improvement + documentation of underlying functions (e.g. |
@lindahua, to catch you up: Yes, I agree that more needs to be done to advertise this. |
Documentation in #10859. |
The team as a whole spends more time being awesome than I have time to keep up with the awesomeness, and I suspect I'm trying harder than the average Julia user. Thanks for highlighting the relevant issues for me. |
Documentation commit: 9b4f212 I also didn't know this was a function for Mortal Men to use in their code, assumed it was just for the Elvish-kings under the Base.sky and Dwarf-lords in their Base.halls of Base.stone. |
Thanks for the PSA! |
You're from New Zealand. Doesn't that count? (Also, it's morning here, and you've added substantially to my enjoyment of it. Thank you.) Would it make sense for something along the lines of "you probably want to use this everywhere you're currently using the range |
It seems we should probably add something to the manual chapter on arrays. |
This already needs rebasing. While I'm at it, what do people think about some of the TODO items above?
|
Man, those are all tough decisions. The choice to make Logical indexing feels like we're still doing it wrong. But I'm not sure how to make it better. See also #10065 (comment). But I agree on punting the algorithm changes to another day, perhaps with a comment in the code about how it could be written better. |
I agree that changing I can rebase this and merge it, and leave hard decisions for another day 😄. |
+1 -- this is really nice... although I'd love to have a shorter name for |
This fixes performance problems for many SubArray operations
Since `done` is called on each iteration but `start` is called only once, it makes more sense to put this logic in `start`.
I realized that my proposal for |
Change `for i=1:length(A)` to `for i in eachindex(A)`
That bitarray segfault on appveyor is worrying... https://ci.appveyor.com/project/StefanKarpinski/julia/build/1.0.3946/job/ius9kwerpcskfbi8 More recent builds have passed though, so maybe it's just a case of #9176? |
The earlier version of this passed on all 3 platforms, and all I did was fix a tiny merge conflict that had nothing to do with BitArrays. So I wasn't worried about this being the cause. |
PSA: when writing algorithms with potentially-multidimensional
AbstractArray
s, please writefor i in eachindex(A)
rather thanfor i = 1:length(A)
whenever you don't have some reason to insist thati
be an integer.This fixes performance problems for many operations (see #1168 (comment)).
There are a few outstanding issues, some of which arise when trying to use one index for two different arrays in circumstances in which we have not previously required the shapes to match:
map!
,julia/base/abstractarray.jl
Line 1300 in ef06211
julia/base/abstractarray.jl
Line 1337 in ef06211
julia/base/array.jl
Line 332 in ef06211
julia/base/array.jl
Line 408 in ef06211
julia/base/array.jl
Line 422 in ef06211
ccopy!
,julia/base/array.jl
Line 1421 in ef06211
and others of which pertain to returning an index to the user (should we return
CartesianIndex
es?)find
,julia/base/array.jl
Line 1150 in ef06211
julia/base/array.jl
Line 1164 in ef06211
findin
,julia/base/array.jl
Line 1271 in ef06211
and finally others where we may want to change the algorithm:
cummin/min/cummax/max
,julia/base/array.jl
Line 1558 in ef06211