Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 0 additions & 22 deletions src/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,6 @@ function ChainRulesCore.rrule(s::Sinus, x::AbstractVector, y::AbstractVector)
return val, evaluate_pullback
end

## Reverse Rules SqMahalanobis

function ChainRulesCore.rrule(
dist::Distances.SqMahalanobis, a::AbstractVector, b::AbstractVector
)
d = dist(a, b)
function SqMahalanobis_pullback(Δ::Real)
a_b = a - b
∂qmat = InplaceableThunk(
X̄ -> mul!(X̄, a_b, a_b', true, Δ), @thunk((a_b * a_b') * Δ)
)
∂a = InplaceableThunk(
X̄ -> mul!(X̄, dist.qmat, a_b, true, 2 * Δ), @thunk((2 * Δ) * dist.qmat * a_b)
)
∂b = InplaceableThunk(
X̄ -> mul!(X̄, dist.qmat, a_b, true, -2 * Δ), @thunk((-2 * Δ) * dist.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)
Expand Down
9 changes: 0 additions & 9 deletions test/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
x = rand(rng, 5)
y = rand(rng, 5)
r = rand(rng, 5)
Q = Matrix(Cholesky(rand(rng, 5, 5), 'U', 0))
@assert isposdef(Q)

compare_gradient(:Zygote, [x, y]) do xy
Euclidean()(xy[1], xy[2])
Expand All @@ -21,11 +19,4 @@
compare_gradient(:Zygote, [x, y]) do xy
KernelFunctions.Sinus(r)(xy[1], xy[2])
end
if VERSION < v"1.6"
@test_broken "Chain rule of SqMahalanobis is broken in Julia pre-1.6"
else
compare_gradient(:Zygote, [Q, x, y]) do Qxy
SqMahalanobis(Qxy[1])(Qxy[2], Qxy[3])
end
end
end