Skip to content

Commit

Permalink
Merge pull request #1494 from FluxML/bc/idset-push!
Browse files Browse the repository at this point in the history
Add rule for `push!(::IdSet)`
  • Loading branch information
ToucheSir authored Oct 13, 2024
2 parents 2517e67 + fe6d2f0 commit 74849f3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ end
end
end

# IdSet (needed for nested AD with implicit params)

grad_mut(::IdSet) = IdSet()

function _pullback(cx::AContext, ::typeof(push!), s::IdSet, @nospecialize(x))
res = push!(s, x)
function idset_push!_pullback(_)
Δ = pop!(grad_mut(cx, s), x, nothing)
(nothing, Δ, nothing)
end
return res, idset_push!_pullback
end

# Dictionaries

grad_mut(d::AbstractDict) = Dict()
Expand Down

0 comments on commit 74849f3

Please sign in to comment.