-
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
Added generic function for abstractvectors #188
Conversation
Bump |
Bump :) |
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.
This looks good to me, except for some minor issues. I should say that this is very hard to tell if it will cause issues with what people may have in their packages, but at least I don't see any.
…ched order of evalutation
Thanks for the review, I included the changes you suggested. I am not sure what you meant by switching the loop orders. I tried to be consistent with the existing implementation, but it should not matter in the end |
I meant to organize the loops in such a way that you write into It seems the org ran out of Travis credits, so CI doesn't work anymore. We need to move to GithubActions... |
Ok then I made the right change.
I can make a PR for that too :) |
I think I have something running on my fork. When tests pass there, I'll kick off the PR. |
I think we can do the same loop swap in the matrix version. It's formally the exact same amount of work, but may benefit from better memory access pattern. To the very least, it shouldn't be worse. |
Tests are failing because of the tests on the |
Codecov Report
@@ Coverage Diff @@
## master #188 +/- ##
==========================================
- Coverage 95.05% 95.04% -0.01%
==========================================
Files 8 8
Lines 688 727 +39
==========================================
+ Hits 654 691 +37
- Misses 34 36 +2
Continue to review full report at Codecov.
|
Awesome! Now let's apply the same trick to the good old matrix-version, and I think this is ready to go. For the |
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.
I have added scalar tests and the required dims
keyword to pairwise
. I suggest to replace the three occurrences of transpose
in generic.jl
by permutedims
, since the first acts recursively, but the dims=1
vs dims=2
distinction is only about the orientation of the outermost array.
@dkarrasch @nalimilan Ok I think all issues are solved now. |
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.
Two small things, and then I think this is ready.
@nalimilan I wonder if it helps FreqTables.jl if we made these pairwise
methods fully generic for iterators, and removed the type constraints on a
and b
. Then the Distances.jl
pairwise method would act metric::PreMetric
.
for i = (j + 1):n | ||
r[i, j] = metric(a[i], a[j]) |
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.
The compiler may do that on its own, but let's be sure:
for i = (j + 1):n | |
r[i, j] = metric(a[i], a[j]) | |
aj = a[j] | |
for i = (j + 1):n | |
r[i, j] = metric(a[i], aj) |
@@ -489,6 +489,8 @@ js_divergence(a::AbstractArray, b::AbstractArray) = JSDivergence()(a, b) | |||
|
|||
result_type(dist::SpanNormDist, a::AbstractArray, b::AbstractArray) = | |||
typeof(eval_op(dist, oneunit(eltype(a)), oneunit(eltype(b)))) | |||
result_type(dist::SpanNormDist, a::AbstractArray{<:AbstractArray}, b::AbstractArray{<:AbstractArray}) = | |||
typeof(eval_op(dist, oneunit(eltype(first(a))), oneunit(eltype(first(b))))) |
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.
typeof(eval_op(dist, oneunit(eltype(first(a))), oneunit(eltype(first(b))))) | |
typeof(eval_op(dist, oneunit(eltype(eltype(a))), oneunit(eltype(eltype(b))))) |
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.
Maybe we should rather override result_type(dist::SpanNormDist, a::Type, b::Type)
and have global generic methods that call this? It sounds suboptimal to redefine methods for different inputs types.
@@ -34,7 +34,7 @@ data `a` and `b`. | |||
""" | |||
result_type(::PreMetric, ::Type, ::Type) = Float64 # fallback | |||
result_type(dist::PreMetric, a::AbstractArray, b::AbstractArray) = result_type(dist, eltype(a), eltype(b)) | |||
|
|||
result_type(dist::PreMetric, a::AbstractArray{<:AbstractArray}, b::AbstractArray{<:AbstractArray}) = result_type(dist, eltype(eltype(a)), eltype(eltype(b))) |
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.
result_type(dist::PreMetric, a::AbstractArray{<:AbstractArray}, b::AbstractArray{<:AbstractArray}) = result_type(dist, eltype(eltype(a)), eltype(eltype(b))) | |
result_type(dist::PreMetric, a::AbstractArray{<:AbstractArray}, b::AbstractArray{<:AbstractArray}) = | |
result_type(dist, eltype(eltype(a)), eltype(eltype(b))) |
pairwise!(r::AbstractMatrix, metric::PreMetric, | ||
a::AbstractVector, b::AbstractVector=a) |
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.
The docstring should explain what happens for vectors. It should probably even be a separate docstring as there's almost nothing in common in the description.
@@ -489,6 +489,8 @@ js_divergence(a::AbstractArray, b::AbstractArray) = JSDivergence()(a, b) | |||
|
|||
result_type(dist::SpanNormDist, a::AbstractArray, b::AbstractArray) = | |||
typeof(eval_op(dist, oneunit(eltype(a)), oneunit(eltype(b)))) | |||
result_type(dist::SpanNormDist, a::AbstractArray{<:AbstractArray}, b::AbstractArray{<:AbstractArray}) = | |||
typeof(eval_op(dist, oneunit(eltype(first(a))), oneunit(eltype(first(b))))) |
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.
Maybe we should rather override result_type(dist::SpanNormDist, a::Type, b::Type)
and have global generic methods that call this? It sounds suboptimal to redefine methods for different inputs types.
The more I think about it, the more I believe this really is not about |
Add supports for vector of vectors by implementing a generic function.
Fixes #152, closes #165, could be extended to #187 (not sure how to dispatch on Iterators in general, but the current implementation would support it)