@@ -16,7 +16,7 @@ function ChainRulesCore.rrule(::DiffractorRuleConfig, g::∇getindex, Δ)
1616 g (Δ), Δ′′-> (nothing , Δ′′[1 ][g. i... ])
1717end
1818
19- function ChainRulesCore. rrule (:: DiffractorRuleConfig , :: typeof (getindex), xs:: Array , i... )
19+ function ChainRulesCore. rrule (:: DiffractorRuleConfig , :: typeof (getindex), xs:: Array{<:Number} , i... )
2020 xs[i... ], ∇getindex (xs, i)
2121end
2222
@@ -220,26 +220,31 @@ struct BackMap{T}
220220end
221221(f:: BackMap{N} )(args... ) where {N} = ∂⃖¹ (getfield (f, :f ), args... )
222222back_apply (x, y) = x (y)
223- back_apply_zero (x) = x (Zero ())
223+ back_apply_zero (x) = x (Zero ()) # Zero is not defined
224224
225225function ChainRules. rrule (:: DiffractorRuleConfig , :: typeof (map), f, args:: Tuple )
226226 a, b = unzip_tuple (map (BackMap (f), args))
227- function back (Δ)
227+ function map_back (Δ)
228228 (fs, xs) = unzip_tuple (map (back_apply, b, Δ))
229229 (NoTangent (), sum (fs), xs)
230230 end
231- function back (Δ:: ZeroTangent )
232- (fs, xs) = unzip_tuple (map (back_apply_zero, b))
233- (NoTangent (), sum (fs), xs)
234- end
235- a, back
231+ map_back (Δ:: AbstractZero ) = (NoTangent (), NoTangent (), NoTangent ())
232+ # function back(Δ::ZeroTangent)
233+ # (fs, xs) = unzip_tuple(map(back_apply_zero, b))
234+ # (NoTangent(), sum(fs), xs)
235+ # end
236+ a, map_back
236237end
237238
239+ ChainRules. rrule (:: DiffractorRuleConfig , :: typeof (map), f, args:: Tuple{} ) = (), _ -> (NoTangent (), NoTangent (), NoTangent ())
240+
238241function ChainRules. rrule (:: DiffractorRuleConfig , :: typeof (Base. ntuple), f, n)
239242 a, b = unzip_tuple (ntuple (BackMap (f), n))
240- a, function (Δ)
243+ function ntuple_back (Δ)
241244 (NoTangent (), sum (map (back_apply, b, Δ)), NoTangent ())
242245 end
246+ ntuple_back (:: AbstractZero ) = (NoTangent (), NoTangent (), NoTangent ())
247+ a, ntuple_back
243248end
244249
245250function ChainRules. frule (:: DiffractorRuleConfig , _, :: Type{Vector{T}} , undef:: UndefInitializer , dims:: Int... ) where {T}
0 commit comments