Skip to content

Commit ac8a900

Browse files
handle nothing-nothing
1 parent 3e00276 commit ac8a900

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/functor.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ children(x) = functor(x)[1]
4646

4747
function functor_tuple(f, x::Tuple, dx::Tuple)
4848
map(x, dx) do x, x̄
49-
fmap1(f, x, x̄)
49+
_default_walk(f, x, x̄)
5050
end
5151
end
5252
functor_tuple(f, x, dx) = f(x, dx)
@@ -66,6 +66,7 @@ function _default_walk(f, x)
6666
func, re = functor(x)
6767
re(map(f, func))
6868
end
69+
_default_walk(f, ::Nothing, ::Nothing) = nothing
6970

7071
"""
7172
fmap(f, x; exclude = isleaf, walk = Functors._default_walk)
@@ -193,5 +194,5 @@ end
193194
# This way we can use `fmap` to update the params with their gradients
194195
function fmap(f, x, dx...; cache = IdDict())
195196
haskey(cache, x) && return cache[x]
196-
cache[x] = isleaf(x) ? f(x, dx...) : fmap1((x...) -> fmap(f, x..., cache = cache), x, dx...)
197+
cache[x] = isleaf(x) ? f(x, dx...) : _default_walk((x...) -> fmap(f, x..., cache = cache), x, dx...)
197198
end

0 commit comments

Comments
 (0)