Skip to content

Commit df8a952

Browse files
committed
add ismutable check
1 parent bfe543a commit df8a952

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/interface.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,12 @@ function _update!(tree, x; grads, params)
7474
haskey(params, (tree,x)) && return params[(tree,x)]
7575
isbits(tree) && return x # means () is not cached, and also (((),),)
7676
x′, re = functor(x)
77-
x′′ = map((tᵢ, xᵢ) -> _update!(tᵢ, xᵢ; grads, params), tree, x′)
78-
params[(tree,x)] = re(x′′)
77+
x′′ = re(map((tᵢ, xᵢ) -> _update!(tᵢ, xᵢ; grads, params), tree, x′))
78+
if ismutable(x′′)
79+
params[(tree,x)] = x′′
80+
else # no ties to preserve between immutable structs, right?
81+
x′′
82+
end
7983
end
8084
function _update!(ℓ::Leaf, x; grads, params)
8185
haskey(params, (ℓ,x)) && return params[(ℓ,x)]

0 commit comments

Comments
 (0)