-
Notifications
You must be signed in to change notification settings - Fork 98
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
use unsafe_views and remove branch for arrays #86
Conversation
@@ -144,7 +144,24 @@ SqEuclidean() = SqEuclidean(0) | |||
# | |||
########################################################### | |||
|
|||
function evaluate(d::UnionMetrics, a::AbstractArray, b::AbstractArray) | |||
# Specialized for Arrays and avoids a branch on the size | |||
@inline function evaluate(d::UnionMetrics, a::T, b::T) where T <: Union{Array, UnsafeVectorView} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note this @inline
. It apparently does quite a lot for the performance with small arrays and it isn't that much code to inline.
I think the unsafe_views beats the split-view API in terms of code-readablity and should be equivalent in terms of speed. I will try to port over the better memory access / multithreaded pairwise!, as well as the modified boundscheck-propagation from my PR; then my the split-views can be dropped. Question: I think distances.jl is unhappy with one-dimensional indices not running from 1:length(V)? As in e.g. offset-arrays? |
Yeah, this package was created a long time ago and the core has been largely unchanged. It is likely it doesn't work well with non one based arrays. We should fix that and test it. |
You can find the more memory-friendly iteration order on https://gist.github.com/chethega/00241c6312d3fe28afc5532708a69b3d. After some testing, I could not see any significant performance gains; therefore, it probably does not belong in Distances.jl. |
On JuliaLang/julia#24113, with normal We could put this in for 0.6 and remove it when tagging a 0.7 release. |
Sure. Then, instead of exporting and cementing the fastview, export and document now something like
and, after removal of fastview, replace it by
and possibly deprecate this a couple versions later? Then one should maybe add boundscheck to fastview, and be happy. |
An alternative for solving #83
cc @chethega