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

More general indexes [2] #15564

Merged
merged 1 commit into from
Mar 21, 2016
Merged

Conversation

dfdx
Copy link
Contributor

@dfdx dfdx commented Mar 19, 2016

Here's a second PR to cover this list of subtasks (from show.jl and to the end of the list).

General idea is to move from a linear integer-based indexing (i.e. for i=1:length(A)) to more general approaches (e.g. for a in A or for a in eachindex(A)) to support wider range of arrays and possibly better optimize code for them.

@@ -550,7 +550,7 @@ function quantile!(q::AbstractArray, v::AbstractVector, p::AbstractArray;
end
isnan(v[end]) && throw(ArgumentError("quantiles are undefined in presence of NaNs"))

for i = 1:length(p)
for i in eachindex(p)
@inbounds q[i] = _quantile(v,p[i])
Copy link
Member

Choose a reason for hiding this comment

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

You should use two different indices for p and q, with zip(eachindex(p), eachindex(q)).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I've updated the code.

@dfdx dfdx force-pushed the more-general-indexing-2 branch from c38521d to e932103 Compare March 19, 2016 22:39
@dfdx dfdx changed the title More general indexes (2) More general indexes [2] Mar 20, 2016
timholy added a commit that referenced this pull request Mar 21, 2016
@timholy timholy merged commit c807bbd into JuliaLang:master Mar 21, 2016
@timholy
Copy link
Member

timholy commented Mar 21, 2016

Looks great, many thanks!

@timholy
Copy link
Member

timholy commented Mar 21, 2016

Just checking, am I correct in the number of items I checked off in #15434?

@dfdx
Copy link
Contributor Author

dfdx commented Mar 21, 2016

@timholy You can also mark as "done" lines with REPLCompletions.jl... (fixed by #15463) and special/erf.jl... (nothing to do).

@@ -426,7 +426,7 @@ function selectperm!{I<:Integer}(ix::AbstractVector{I}, v::AbstractVector,
order::Ordering=Forward,
initialized::Bool=false)
if !initialized
@inbounds for i = 1:length(ix)
@inbounds for i in eachindex(ix)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is right, you're storing the index in the permutation vector

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't know about that. Do you have specific type of permutation in mind?

I'll create a PR to fix this.

Copy link
Contributor

Choose a reason for hiding this comment

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

AbstractVector{I<:Integer} is the signature. similar below insortperm!

Copy link
Member

Choose a reason for hiding this comment

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

@timholy Maybe we should be a bit more careful before merging this kind of change? As we have seen, it can be more tricky than it sounds to check that all modifications make sense.

Copy link
Member

Choose a reason for hiding this comment

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

I am slightly uneasy about all this from a performance point of view. From what I have seen before, it is quite easy to accidentally introduce a 20-30% regression by causing something to not inline anymore. I know you have done some benchmarks with zip etc but are they valid in all cases that are being changed in all these PRs? To me, something like this would be better in a separate branch and then running the benchmark suite on the whole thing,

Copy link
Member

Choose a reason for hiding this comment

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

Shoot, clearly I need to expand the context when reviewing these (and perhaps not do it late at night). Yes, this falls under the "relying on the representation" clause.

Slightly radical thought, but I wonder if we should consider making all array indexes return their "context", so they can be converted into some kind of canonical form? For example, as an immutable with size information, so that linear<->cartesian transformations are possible when holding just the index. I don't think we want to go there yet, but it's something to keep in mind.

@KristofferC, I take your point. I don't want to make folks tackle too much, so in the future let's just run the benchmarks even on smaller PRs.

Also keep in mind that in many cases, this could become a performance win; in general, iteration with eachindex is no slower, and sometimes much much faster, than for i = 1:n iteration.

dfdx pushed a commit to dfdx/julia that referenced this pull request Mar 21, 2016
tkelman added a commit that referenced this pull request Mar 23, 2016
Fix for indexing issue introduced in #15564
JeffBezanson pushed a commit that referenced this pull request Mar 23, 2016
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