Skip to content
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

Qualify pairwise call #360

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
v = randn(rng, D)
w = randn(rng, N)

@testset "check_args macro" begin
@test_throws ArgumentError GammaExponentialKernel(-1.0, Euclidean())
end

@testset "VecOfVecs" begin
@test vec_of_vecs(X; obsdim=2) == ColVecs(X)
@test vec_of_vecs(X; obsdim=1) == RowVecs(X)
Expand Down Expand Up @@ -42,6 +46,10 @@
KernelFunctions.pairwise!(K, SqEuclidean(), DX, DY)
@test K ≈ pairwise(SqEuclidean(), X, Y; dims=2)

y = rand(N, 1)
yv = y[:]
@test RowVecs(y) == RowVecs(yv)

let
@test Zygote.pullback(ColVecs, X)[1] == DX
DX, back = Zygote.pullback(ColVecs, X)
Expand Down Expand Up @@ -98,14 +106,40 @@
x_rowvecs = RowVecs(randn(7, 3))

@test isapprox(
pairwise(SqEuclidean(), x_colvecs, x_rowvecs),
KernelFunctions.pairwise(SqEuclidean(), x_colvecs, x_rowvecs),
pairwise(SqEuclidean(), collect(x_colvecs), collect(x_rowvecs)),
)
@test isapprox(
pairwise(SqEuclidean(), x_rowvecs, x_colvecs),
KernelFunctions.pairwise(SqEuclidean(), x_rowvecs, x_colvecs),
pairwise(SqEuclidean(), collect(x_rowvecs), collect(x_colvecs)),
)
end
@testset "AbstractVector + RowVecs" begin
x = [randn(3) for _ in 1:5]
x_rowvecs = RowVecs(randn(7, 3))

@test isapprox(
KernelFunctions.pairwise(SqEuclidean(), x, x_rowvecs),
pairwise(SqEuclidean(), x, collect(x_rowvecs)),
)
@test isapprox(
KernelFunctions.pairwise(SqEuclidean(), x_rowvecs, x),
pairwise(SqEuclidean(), collect(x_rowvecs), x),
)
end
@testset "AbstractVector + ColVecs" begin
x = [randn(3) for _ in 1:5]
x_colvecs = ColVecs(randn(3, 7))

@test isapprox(
KernelFunctions.pairwise(SqEuclidean(), x, x_colvecs),
pairwise(SqEuclidean(), x, collect(x_colvecs)),
)
@test isapprox(
KernelFunctions.pairwise(SqEuclidean(), x_colvecs, x),
pairwise(SqEuclidean(), collect(x_colvecs), x),
)
end
@testset "input checks" begin
D = 3
D⁻ = 2
Expand Down