1
1
# Int rather than Int64/Integer is intentional
2
- function frule ((_, ẋ), :: typeof (getfield), x:: Tuple , i:: Int )
3
- return x. i, ẋ. i
2
+ function ChainRulesCore. frule ((_, Δ, _), :: typeof (getfield), strct, sym:: Union{Int,Symbol} )
3
+ return (getfield (strct, sym), isa (Δ, NoTangent) ? NoTangent () : getproperty (Δ, sym))
4
+ end
5
+
6
+ function ChainRulesCore. frule ((_, Δ, _, _), :: typeof (getfield), strct, sym:: Union{Int,Symbol} , inbounds)
7
+ return (getfield (strct, sym, inbounds), isa (Δ, NoTangent) ? NoTangent () : getproperty (Δ, sym))
4
8
end
5
9
6
10
" for a given tuple type, returns a Val{N} where N is the length of the tuple"
@@ -21,7 +25,6 @@ function rrule(::typeof(getindex), x::T, i::Integer) where {T<:NTuple{<:Any,<:Nu
21
25
dx = ntuple (j -> j == i ? dy : zero (dy), _tuple_N (T))
22
26
return (NoTangent (), Tangent {T} (dx... ), NoTangent ())
23
27
end
24
- return x[i], getindex_back_2
25
28
end
26
29
27
30
# Note Zygote has getindex(::Tuple, ::UnitRange) separately from getindex(::Tuple, ::AbstractVector),
0 commit comments