@@ -45,7 +45,7 @@ function _setup(rule, x; cache)
4545 cache[x] = ℓ
4646 end
4747 else
48- valuemap (xᵢ -> _setup (rule, xᵢ; cache), _trainable (x))
48+ mapvalue (xᵢ -> _setup (rule, xᵢ; cache), _trainable (x))
4949 end
5050end
5151
@@ -82,7 +82,7 @@ function _update!(tree, x; grads, params)
8282 haskey (params, (tree,x)) && return params[(tree,x)]
8383 isbits (tree) && return x # means () is not cached, and also (((),),)
8484 x′, re = functor (x)
85- x′′ = re (valuemap ((tᵢ, xᵢ) -> _update! (tᵢ, xᵢ; grads, params), tree, x′))
85+ x′′ = re (mapvalue ((tᵢ, xᵢ) -> _update! (tᵢ, xᵢ; grads, params), tree, x′))
8686 if ismutable (x′′)
8787 params[(tree,x)] = x′′
8888 else # no ties to preserve between immutable structs, right?
@@ -115,7 +115,7 @@ function _grads!(dict::IdDict, tree, x, x̄s...)
115115 # functor(typeof(tree), base(x̄)), for things like Transpose
116116 x̄s′ = map (x̄ -> functor (typeof (x), base (x̄))[1 ], x̄s)
117117 x′, _ = functor (typeof (x), x)
118- valueforeach ((tᵢ, xᵢ, x̄sᵢ... ) -> _grads! (dict, tᵢ, xᵢ, x̄sᵢ... ), tree, x′, x̄s′... )
118+ foreachvalue ((tᵢ, xᵢ, x̄sᵢ... ) -> _grads! (dict, tᵢ, xᵢ, x̄sᵢ... ), tree, x′, x̄s′... )
119119end
120120
121121# default all rules to first order calls
@@ -172,21 +172,14 @@ _trainable(x) = _trainable(functor(x)[1], trainable(x))
172172_trainable (ch:: NamedTuple , tr:: NamedTuple ) = merge (map (_ -> nothing , ch), tr)
173173_trainable (ch:: Tuple{Vararg{Any,N}} , tr:: Tuple{Vararg{Any,N}} ) where N = tr
174174_trainable (ch:: AbstractArray , tr:: AbstractArray ) = tr
175- _trainable (ch:: Dict , tr:: Dict ) = merge (valuemap (_ -> nothing , ch), tr)
175+ _trainable (ch:: Dict , tr:: Dict ) = merge (mapvalue (_ -> nothing , ch), tr)
176176
177177function _trainable (ch:: NamedTuple , tr:: Tuple ) # for old Flux-style no-names tuple
178178 @warn " trainable(x) should now return a NamedTuple with the field names, not a Tuple" maxlog= 3
179179 map (c -> c in tr ? c : nothing , ch)
180180end
181181
182182
183- valuemap (f, x... ) = map (f, x... )
184- valuemap (f, x:: Dict , ys... ) = Dict (k => f (v, (get (y, k, nothing ) for y in ys). .. ) for (k,v) in x)
185- valueforeach (f, x... ) = foreach (f, x... )
186- valueforeach (f, x:: Dict , ys... ) = foreach (pairs (x)) do (k, v)
187- f (v, (get (y, k, nothing ) for y in ys). .. )
188- end
189-
190183
191184# ##
192185# ## rule definition helpers
0 commit comments