Skip to content
Merged
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
8 changes: 5 additions & 3 deletions ext/ReferenceFrameRotationsZygoteExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ using ReferenceFrameRotations
using ForwardDiff

using Zygote.ChainRulesCore: ChainRulesCore
import Zygote.ChainRulesCore: NoTangent
import Zygote.ChainRulesCore: NoTangent, unthunk

function ChainRulesCore.rrule(::Type{<:DCM}, data::NTuple{9, T}) where {T}
y = DCM(data)

function DCM_pullback(Δ)
return (NoTangent(), Tuple(Δ))
Δ_unthunked = unthunk(Δ)
return (NoTangent(), Tuple(Δ_unthunked))
end

return y, DCM_pullback
Expand All @@ -26,8 +27,9 @@ function ChainRulesCore.rrule(::typeof(orthonormalize), dcm::DCM)
y = orthonormalize(dcm)

function orthonormalize_pullback(Δ)
Δ_unthunked = unthunk(Δ)
jac = ForwardDiff.jacobian(orthonormalize, dcm)
return (NoTangent(), reshape(vcat(Δ...)' * jac, 3, 3))
return (NoTangent(), reshape(vcat(Δ_unthunked...)' * jac, 3, 3))
end

return y, orthonormalize_pullback
Expand Down
Loading