-
Notifications
You must be signed in to change notification settings - Fork 36
Testing (and fixing) handling of AbstractVector{AbstractVector{T}} inputs #370
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
Changes from all commits
d72a72f
497a498
84c09cc
9dba0c6
f537ddf
10ac9ee
e6d417b
7ac8e90
91cc6c0
742011a
9d1c413
ba14ad9
ee2b5ec
9660692
7581726
4d3b80a
682659f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,10 @@ | ||
# Delta is not following the PreMetric rules since d(x, x) == 1 | ||
struct Delta <: Distances.UnionPreMetric end | ||
|
||
@inline function Distances._evaluate(::Delta, a::AbstractVector, b::AbstractVector) | ||
@boundscheck if length(a) != length(b) | ||
throw( | ||
DimensionMismatch( | ||
"first array has length $(length(a)) which does not match the length of the " * | ||
"second, $(length(b)).", | ||
), | ||
) | ||
end | ||
return a == b | ||
end | ||
|
||
Distances.result_type(::Delta, Ta::Type, Tb::Type) = Bool | ||
|
||
@inline Distances.eval_op(::Delta, a::Real, b::Real) = a == b | ||
@inline Distances.eval_reduce(::Delta, a, b) = a && b | ||
@inline Distances.eval_start(::Delta, a, b) = true | ||
@inline (dist::Delta)(a::AbstractArray, b::AbstractArray) = Distances._evaluate(dist, a, b) | ||
@inline (dist::Delta)(a::Number, b::Number) = a == b | ||
|
||
Distances.result_type(::Delta, Ta::Type, Tb::Type) = Bool |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -133,6 +133,18 @@ function test_interface( | |||||
) | ||||||
end | ||||||
|
||||||
function test_interface( | ||||||
rng::AbstractRNG, k::Kernel, ::Type{<:Vector{Vector{T}}}; dim_in=2, kwargs... | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Sorry what's the reasoning for not using this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test itself utilises a |
||||||
) where {T<:Real} | ||||||
return test_interface( | ||||||
k, | ||||||
[randn(rng, T, dim_in) for _ in 1:1001], | ||||||
[randn(rng, T, dim_in) for _ in 1:1001], | ||||||
[randn(rng, T, dim_in) for _ in 1:1000]; | ||||||
kwargs..., | ||||||
) | ||||||
end | ||||||
|
||||||
function test_interface(k::Kernel, T::Type{<:AbstractVector}; kwargs...) | ||||||
return test_interface(Random.GLOBAL_RNG, k, T; kwargs...) | ||||||
end | ||||||
|
@@ -147,6 +159,9 @@ function test_interface(rng::AbstractRNG, k::Kernel, T::Type{<:Real}; kwargs...) | |||||
@testset "RowVecs{$T}" begin | ||||||
test_interface(rng, k, RowVecs{T}; kwargs...) | ||||||
end | ||||||
@testset "Vector{Vector{T}}" begin | ||||||
test_interface(rng, k, Vector{Vector{T}}; kwargs...) | ||||||
end | ||||||
end | ||||||
|
||||||
function test_interface(k::Kernel, T::Type{<:Real}=Float64; kwargs...) | ||||||
|
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 will result in much more complicated code, I don't think we should use the default dispatches in Distances and implement these internal functions.
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.
We should just have to check
x == y
for the inputsx
andy
.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.
Is there even a reason to implement
Distances._evaluate
here? Isn't(::Delta)(x, y)
sufficient?