Skip to content

Bump ChainRulesCore #293

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 2 commits into from
Jun 2, 2021
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.2"
version = "0.10.3"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand All @@ -20,7 +20,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444"

[compat]
ChainRulesCore = "0.9"
ChainRulesCore = "0.9.44, 0.10"
Compat = "3.7"
CompositionsBase = "0.1"
Distances = "0.10"
Expand Down
2 changes: 1 addition & 1 deletion src/KernelFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export IndependentMOKernel, LatentFactorMOKernel, IntrinsicCoregionMOKernel
export tensor, ⊗, compose

using Compat
using ChainRulesCore: ChainRulesCore, Composite, Zero, One, DoesNotExist, NO_FIELDS
using ChainRulesCore: ChainRulesCore, Tangent, ZeroTangent, One, DoesNotExist, NoTangent
using ChainRulesCore: @thunk, InplaceableThunk
using CompositionsBase
using Distances
Expand Down
26 changes: 13 additions & 13 deletions src/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end
function ChainRulesCore.rrule(dist::Delta, x::AbstractVector, y::AbstractVector)
d = dist(x, y)
function evaluate_pullback(::Any)
return NO_FIELDS, Zero(), Zero()
return NoTangent(), ZeroTangent(), ZeroTangent()
end
return d, evaluate_pullback
end
Expand All @@ -27,7 +27,7 @@ function ChainRulesCore.rrule(
)
P = Distances.pairwise(d, X, Y; dims=dims)
function pairwise_pullback(::AbstractMatrix)
return NO_FIELDS, NO_FIELDS, Zero(), Zero()
return NoTangent(), NoTangent(), ZeroTangent(), ZeroTangent()
end
return P, pairwise_pullback
end
Expand All @@ -37,7 +37,7 @@ function ChainRulesCore.rrule(
)
P = Distances.pairwise(d, X; dims=dims)
function pairwise_pullback(::AbstractMatrix)
return NO_FIELDS, NO_FIELDS, Zero()
return NoTangent(), NoTangent(), ZeroTangent()
end
return P, pairwise_pullback
end
Expand All @@ -47,7 +47,7 @@ function ChainRulesCore.rrule(
)
C = Distances.colwise(d, X, Y)
function colwise_pullback(::AbstractVector)
return NO_FIELDS, NO_FIELDS, Zero(), Zero()
return NoTangent(), NoTangent(), ZeroTangent(), ZeroTangent()
end
return C, colwise_pullback
end
Expand All @@ -57,7 +57,7 @@ end
function ChainRulesCore.rrule(dist::DotProduct, x::AbstractVector, y::AbstractVector)
d = dist(x, y)
function evaluate_pullback(Δ::Any)
return NO_FIELDS, Δ .* y, Δ .* x
return NoTangent(), Δ .* y, Δ .* x
end
return d, evaluate_pullback
end
Expand All @@ -72,9 +72,9 @@ function ChainRulesCore.rrule(
P = Distances.pairwise(d, X, Y; dims=dims)
function pairwise_pullback_cols(Δ::AbstractMatrix)
if dims == 1
return NO_FIELDS, NO_FIELDS, Δ * Y, Δ' * X
return NoTangent(), NoTangent(), Δ * Y, Δ' * X
else
return NO_FIELDS, NO_FIELDS, Y * Δ', X * Δ
return NoTangent(), NoTangent(), Y * Δ', X * Δ
end
end
return P, pairwise_pullback_cols
Expand All @@ -86,9 +86,9 @@ function ChainRulesCore.rrule(
P = Distances.pairwise(d, X; dims=dims)
function pairwise_pullback_cols(Δ::AbstractMatrix)
if dims == 1
return NO_FIELDS, NO_FIELDS, 2 * Δ * X
return NoTangent(), NoTangent(), 2 * Δ * X
else
return NO_FIELDS, NO_FIELDS, 2 * X * Δ
return NoTangent(), NoTangent(), 2 * X * Δ
end
end
return P, pairwise_pullback_cols
Expand All @@ -99,7 +99,7 @@ function ChainRulesCore.rrule(
)
C = Distances.colwise(d, X, Y)
function colwise_pullback(Δ::AbstractVector)
return NO_FIELDS, NO_FIELDS, Δ' .* Y, Δ' .* X
return NoTangent(), NoTangent(), Δ' .* Y, Δ' .* X
end
return C, colwise_pullback
end
Expand Down Expand Up @@ -135,15 +135,15 @@ function ChainRulesCore.rrule(
∂b = InplaceableThunk(
@thunk((-2 * Δ) * dist.qmat * a_b), X̄ -> mul!(X̄, dist.qmat, a_b, true, -2 * Δ)
)
return Composite{typeof(dist)}(; qmat=∂qmat), ∂a, ∂b
return Tangent{typeof(dist)}(; qmat=∂qmat), ∂a, ∂b
end
return d, SqMahalanobis_pullback
end

## Reverse Rules for matrix wrappers

function ChainRulesCore.rrule(::Type{<:ColVecs}, X::AbstractMatrix)
ColVecs_pullback(Δ::Composite) = (NO_FIELDS, Δ.X)
ColVecs_pullback(Δ::Tangent) = (NoTangent(), Δ.X)
function ColVecs_pullback(::AbstractVector{<:AbstractVector{<:Real}})
return error(
"Pullback on AbstractVector{<:AbstractVector}.\n" *
Expand All @@ -155,7 +155,7 @@ function ChainRulesCore.rrule(::Type{<:ColVecs}, X::AbstractMatrix)
end

function ChainRulesCore.rrule(::Type{<:RowVecs}, X::AbstractMatrix)
RowVecs_pullback(Δ::Composite) = (NO_FIELDS, Δ.X)
RowVecs_pullback(Δ::Tangent) = (NoTangent(), Δ.X)
function RowVecs_pullback(::AbstractVector{<:AbstractVector{<:Real}})
return error(
"Pullback on AbstractVector{<:AbstractVector}.\n" *
Expand Down