Skip to content

Commit

Permalink
convert the AbstractZero to nothing just before the API
Browse files Browse the repository at this point in the history
  • Loading branch information
Miha Zgubic committed Sep 9, 2020
1 parent dd34364 commit 8d690d7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/compiler/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ _pullback(f, args...) = _pullback(Context(), f, args...)
tailmemaybe(::Nothing) = nothing
tailmemaybe(x::Tuple) = Base.tail(x)

replacezero(t) = ntuple(i -> t[i] isa AbstractZero ? nothing : t[i], length(t))
replacezero(::Nothing) = nothing
replacezero(::AbstractZero) = nothing

function pullback(f, args...)
y, back = _pullback(f, args...)
y, Δ -> tailmemaybe(back(Δ))
y, Δ -> replacezero(tailmemaybe(back)))
end

sensitivity(y::Number) = one(y)
Expand Down

0 comments on commit 8d690d7

Please sign in to comment.