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

Stop using deprecated signatures from Distances.jl #529

Merged
merged 4 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "KernelFunctions"
uuid = "ec8451be-7e33-11e9-00cf-bbf324bd1392"
version = "0.10.57"
version = "0.10.58"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand All @@ -25,7 +25,7 @@ ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444"
ChainRulesCore = "1"
Compat = "3.7, 4"
CompositionsBase = "0.1"
Distances = "0.10"
Distances = "0.10.9"
FillArrays = "0.10, 0.11, 0.12, 0.13, 1"
Functors = "0.1, 0.2, 0.3, 0.4"
IrrationalConstants = "0.1, 0.2"
Expand Down
4 changes: 2 additions & 2 deletions src/basekernels/fbm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

function kernelmatrix!(K::AbstractMatrix, κ::FBMKernel, x::AbstractVector)
modx = _mod(x)
pairwise!(K, SqEuclidean(), x)
pairwise!(SqEuclidean(), K, x)

Check warning on line 60 in src/basekernels/fbm.jl

View check run for this annotation

Codecov / codecov/patch

src/basekernels/fbm.jl#L60

Added line #L60 was not covered by tests
K .= _fbm.(modx, modx', K, κ.h)
return K
end
Expand All @@ -72,7 +72,7 @@
function kernelmatrix!(
K::AbstractMatrix, κ::FBMKernel, x::AbstractVector, y::AbstractVector
)
pairwise!(K, SqEuclidean(), x, y)
pairwise!(SqEuclidean(), K, x, y)

Check warning on line 75 in src/basekernels/fbm.jl

View check run for this annotation

Codecov / codecov/patch

src/basekernels/fbm.jl#L75

Added line #L75 was not covered by tests
K .= _fbm.(_mod(x), _mod(y)', K, κ.h)
return K
end
Expand Down
12 changes: 6 additions & 6 deletions src/distances/pairwise.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ end

pairwise(d::PreMetric, X::AbstractVector) = pairwise(d, X, X)

function pairwise!(out::AbstractMatrix, d::PreMetric, X::AbstractVector, Y::AbstractVector)
function pairwise!(d::PreMetric, out::AbstractMatrix, X::AbstractVector, Y::AbstractVector)
simsurace marked this conversation as resolved.
Show resolved Hide resolved
return broadcast!(d, out, X, permutedims(Y))
end

pairwise!(out::AbstractMatrix, d::PreMetric, X::AbstractVector) = pairwise!(out, d, X, X)
pairwise!(d::PreMetric, out::AbstractMatrix, X::AbstractVector) = pairwise!(d, out, X, X)

function pairwise(d::PreMetric, x::AbstractVector{<:Real})
return Distances_pairwise(d, reshape(x, :, 1); dims=1)
Expand All @@ -20,14 +20,14 @@ function pairwise(d::PreMetric, x::AbstractVector{<:Real}, y::AbstractVector{<:R
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)
function pairwise!(d::PreMetric, out::AbstractMatrix, x::AbstractVector{<:Real})
return Distances.pairwise!(d, out, reshape(x, :, 1); dims=1)
end

function pairwise!(
out::AbstractMatrix, d::PreMetric, x::AbstractVector{<:Real}, y::AbstractVector{<:Real}
d::PreMetric, out::AbstractMatrix, x::AbstractVector{<:Real}, y::AbstractVector{<:Real}
)
return Distances.pairwise!(out, d, reshape(x, :, 1), reshape(y, :, 1); dims=1)
return Distances.pairwise!(d, out, reshape(x, :, 1), reshape(y, :, 1); dims=1)
end

# Also defines the colwise method for abstractvectors
Expand Down
4 changes: 2 additions & 2 deletions src/matrix/kernelmatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ kernelmatrix_diag(κ::Kernel, x::AbstractVector, y::AbstractVector) = map(κ, x,

function kernelmatrix!(K::AbstractMatrix, κ::SimpleKernel, x::AbstractVector)
validate_inplace_dims(K, x)
pairwise!(K, metric(κ), x)
pairwise!(metric(κ), K, x)
return map!(x -> kappa(κ, x), K, K)
end

function kernelmatrix!(
K::AbstractMatrix, κ::SimpleKernel, x::AbstractVector, y::AbstractVector
)
validate_inplace_dims(K, x, y)
pairwise!(K, metric(κ), x, y)
pairwise!(metric(κ), K, x, y)
return map!(x -> kappa(κ, x), K, K)
end

Expand Down
16 changes: 8 additions & 8 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ end
function pairwise(d::PreMetric, x::ColVecs, y::AbstractVector{<:AbstractVector{<:Real}})
return Distances_pairwise(d, x.X, reduce(hcat, y); dims=2)
end
function pairwise!(out::AbstractMatrix, d::PreMetric, x::ColVecs)
return Distances.pairwise!(out, d, x.X; dims=2)
function pairwise!(d::PreMetric, out::AbstractMatrix, x::ColVecs)
return Distances.pairwise!(d, out, x.X; dims=2)
end
function pairwise!(out::AbstractMatrix, d::PreMetric, x::ColVecs, y::ColVecs)
return Distances.pairwise!(out, d, x.X, y.X; dims=2)
function pairwise!(d::PreMetric, out::AbstractMatrix, x::ColVecs, y::ColVecs)
return Distances.pairwise!(d, out, x.X, y.X; dims=2)
end

"""
Expand Down Expand Up @@ -178,11 +178,11 @@ end
function pairwise(d::PreMetric, x::RowVecs, y::AbstractVector{<:AbstractVector{<:Real}})
return Distances_pairwise(d, x.X, permutedims(reduce(hcat, y)); dims=1)
end
function pairwise!(out::AbstractMatrix, d::PreMetric, x::RowVecs)
return Distances.pairwise!(out, d, x.X; dims=1)
function pairwise!(d::PreMetric, out::AbstractMatrix, x::RowVecs)
return Distances.pairwise!(d, out, x.X; dims=1)
end
function pairwise!(out::AbstractMatrix, d::PreMetric, x::RowVecs, y::RowVecs)
return Distances.pairwise!(out, d, x.X, y.X; dims=1)
function pairwise!(d::PreMetric, out::AbstractMatrix, x::RowVecs, y::RowVecs)
return Distances.pairwise!(d, out, x.X, y.X; dims=1)
end

# Resolve ambiguity error for ColVecs vs RowVecs. #346
Expand Down
6 changes: 3 additions & 3 deletions test/distances/pairwise.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

@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)
KernelFunctions.pairwise!(d, K, x, y)
@test K ≈ pairwise(d, X, Y; dims=2)
K = zeros(Ns[1], Ns[1])
KernelFunctions.pairwise!(K, d, x)
KernelFunctions.pairwise!(d, K, x)
@test K ≈ pairwise(d, X; dims=2)

x = randn(rng, 10)
Expand All @@ -24,6 +24,6 @@
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)
KernelFunctions.pairwise!(d, K, x, y)
@test K ≈ pairwise(d, X, Y; dims=1)
end
8 changes: 4 additions & 4 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
@test vcat(DX, DY) isa ColVecs
@test vcat(DX, DY).X == hcat(X, Y)
K = zeros(N, N)
KernelFunctions.pairwise!(K, SqEuclidean(), DX)
KernelFunctions.pairwise!(SqEuclidean(), K, DX)
@test K ≈ pairwise(SqEuclidean(), X; dims=2)
K = zeros(N, N + 1)
KernelFunctions.pairwise!(K, SqEuclidean(), DX, DY)
KernelFunctions.pairwise!(SqEuclidean(), K, DX, DY)
@test K ≈ pairwise(SqEuclidean(), X, Y; dims=2)

let
Expand Down Expand Up @@ -105,10 +105,10 @@
@test vcat(DX, DY) isa RowVecs
@test vcat(DX, DY).X == vcat(X, Y)
K = zeros(D, D)
KernelFunctions.pairwise!(K, SqEuclidean(), DX)
KernelFunctions.pairwise!(SqEuclidean(), K, DX)
@test K ≈ pairwise(SqEuclidean(), X; dims=1)
K = zeros(D, D + 1)
KernelFunctions.pairwise!(K, SqEuclidean(), DX, DY)
KernelFunctions.pairwise!(SqEuclidean(), K, DX, DY)
@test K ≈ pairwise(SqEuclidean(), X, Y; dims=1)

let
Expand Down
Loading