-
Notifications
You must be signed in to change notification settings - Fork 36
Fixes #115 #123
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
Merged
Merged
Fixes #115 #123
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
254adbe
Created pairwise for vector of vectors
theogf 9d30280
Added SliceMap to be used with FunctionTransform
theogf 1b8d330
Moved and added tests for pairwise
theogf 6ef917f
Missing pairwise in runtests
theogf 19b7061
Removed SliceMap
theogf 5309679
Made separate pairwise for KernelFunctions.jl
theogf 39c90b8
Merge branch 'master' into fix_transform
theogf 32cd334
Fixed all tests
theogf 160b53c
Adding missing uncovered line
theogf 534e490
Update src/distances/pairwise.jl
theogf dd5fa10
Update src/distances/pairwise.jl
theogf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Add our own pairwise function to be able to apply it on vectors | ||
|
||
function pairwise(d::PreMetric, X::AbstractVector, Y::AbstractVector) | ||
broadcast(d, X, Y') | ||
end | ||
|
||
pairwise(d::PreMetric, X::AbstractVector) = pairwise(d, X, X) | ||
|
||
function pairwise!( | ||
out::AbstractMatrix, | ||
d::PreMetric, | ||
X::AbstractVector, | ||
Y::AbstractVector, | ||
) | ||
broadcast!(d, out, X, Y') | ||
end | ||
|
||
pairwise!(out::AbstractMatrix, d::PreMetric, X::AbstractVector) = | ||
pairwise!(out, d, X, X) | ||
theogf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function pairwise(d::PreMetric, x::AbstractVector{<:Real}) | ||
return Distances.pairwise(d, reshape(x, :, 1); dims = 1) | ||
end | ||
|
||
function pairwise( | ||
d::PreMetric, | ||
x::AbstractVector{<:Real}, | ||
y::AbstractVector{<:Real}, | ||
) | ||
return Distances.pairwise(d, reshape(x, :, 1), reshape(y, :, 1); dims = 1) | ||
end | ||
|
||
function pairwise!(out::AbstractMatrix, d::PreMetric, x::AbstractVector{<:Real}) | ||
return Distances.pairwise!(out, d, reshape(x, :, 1); dims = 1) | ||
end | ||
|
||
function pairwise!( | ||
out::AbstractMatrix, | ||
d::PreMetric, | ||
x::AbstractVector{<:Real}, | ||
y::AbstractVector{<:Real}, | ||
) | ||
return Distances.pairwise!(out, d, reshape(x, :, 1), reshape(y, :, 1); dims=1) | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@testset "pairwise" begin | ||
rng = MersenneTwister(123456) | ||
d = SqEuclidean() | ||
Ns = (4, 5) | ||
D = 3 | ||
x = [randn(rng, D) for _ in 1:Ns[1]] | ||
y = [randn(rng, D) for _ in 1:Ns[2]] | ||
X = hcat(x...) | ||
Y = hcat(y...) | ||
K = zeros(Ns) | ||
|
||
@test KernelFunctions.pairwise(d, x, y) ≈ pairwise(d, X, Y, dims=2) | ||
@test KernelFunctions.pairwise(d, x) ≈ pairwise(d, X, dims=2) | ||
KernelFunctions.pairwise!(K, d, x, y) | ||
@test K ≈ pairwise(d, X, Y, dims=2) | ||
K = zeros(Ns[1], Ns[1]) | ||
KernelFunctions.pairwise!(K, d, x) | ||
@test K ≈ pairwise(d, X, dims=2) | ||
|
||
x = randn(rng, 10) | ||
X = reshape(x, :, 1) | ||
y = randn(rng, 11) | ||
Y = reshape(y, :, 1) | ||
K = zeros(10, 11) | ||
@test KernelFunctions.pairwise(d, x, y) ≈ pairwise(d, X, Y; dims=1) | ||
@test KernelFunctions.pairwise(d, x) ≈ pairwise(d, X; dims=1) | ||
KernelFunctions.pairwise!(K, d, x, y) | ||
@test K ≈ pairwise(d, X, Y, dims=1) | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.