-
-
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
Improved sparse getindex #7131
Improved sparse getindex #7131
Conversation
Now faster and uses less memory in most common cases.
A factor of 0 would never return, so I assume you mean 1. :-) Anyway, the timings are impressive! |
Yep, 1, as in no improvement (now corrected). Tnx. |
This is really great, and much needed improvement. The performance tests are nice too. Could you add them to the |
@tanmaykm This will probably conflict with the |
That was swift work! I'll have a look at |
@mauro3 Keep 'em coming! I see you work quite a bit with sparse matrices, on your homepage. It would be great if you can keep pushing the limits. |
The
Even converting the indices to Int32 doesn't work because the expression for the last argument in the call to
|
Ha, I thought it unlikely that this would be bug free. Thanks! The function binarysearch{Ti<:Integer}(haystack::AbstractVector{Ti}, needle, lo::Ti, hi::Ti)
# Finds the first occurrence of needle in haystack[lo:hi]
lo = lo-1
hi2 = hi
hi = hi+1
@inbounds while lo < hi-1
m = (lo+hi)>>>1
if haystack[m] < needle
lo = m
else
hi = m
end
end
(hi==hi2+1 || haystack[hi]!=needle) ? 0 : hi
end plus a few other changes. I don't have time to do it now but I'll try tomorrow. |
Is there a reason you're reimplementing |
@kmsquire: you mean with respect to the ones in |
Made PR with performance tests I used for this: #7177 |
also replaced binarysearch with methods from sort.jl ref JuliaLang#7131, JuliaLang#7047
This PR improves the sparse getindex performance. Execution time is shorter by a factor of 1 to 500 on the (somewhat primitive) examples I ran, memory usage is down by a factor of 1 to 5000. The performance
tests and results are here: https://gist.github.com/mauro3/7f01931b5f25d7b397af
Updates:
speedup & memory gain).
the original getindex_general (some large speed-ups/memory gains as well)
(therefore no gains)
getindex & related functions