You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package probably wants a way to write mapreduce, to replace e.g. sum(norm(p) for p in params(m)) in Flux. This seems like the minimal attempt, but it's not Zygote-friendly. Can this be fixed, and is there a better way?
julia>using Functors, Zygote
julia>const INIT = Base._InitialValue();
julia>functionfmapreduce(f, op, x; init = INIT, walk = (f, x) ->foreach(f, Functors.children(x)), kw...)
fmap(x; walk, kw...) do y
init = init===INIT ?f(y) :op(init, f(y))
end
init===INIT ? Base.mapreduce_empty(f, op) : init
end
fmapreduce (generic function with 1 method)
julia> m = ([1,2], (x=[3,4], y=5), 6);
julia>fmapreduce(sum, +, m)
21
julia>gradient(fmapreduce, sum, +, m)
(nothing, nothing, nothing)
The text was updated successfully, but these errors were encountered:
This package probably wants a way to write
mapreduce
, to replace e.g.sum(norm(p) for p in params(m))
in Flux. This seems like the minimal attempt, but it's not Zygote-friendly. Can this be fixed, and is there a better way?The text was updated successfully, but these errors were encountered: