Skip to content

Commit

Permalink
namedtuple getfield, for iteration
Browse files Browse the repository at this point in the history
Co-Authored-By: dhairyagandhi96 <dhairya@juliacopmuting.com>
  • Loading branch information
MikeInnes and dhairyagandhi96 committed Oct 14, 2019
1 parent 16b9aea commit 0d5df1b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib/lib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ end
@adjoint Core.getfield(xs::NTuple{N,Any}, i::Integer) where N =
(xs[i], Δ -> (ntuple(j -> i == j ? Δ : nothing, Val(N)), nothing))

@adjoint Core.getfield(xs::NamedTuple{K,<:NTuple{N,Any}}, i::Integer) where {K,N} =
(xs[i], Δ -> (NamedTuple{K}(ntuple(j -> i == j ? Δ : nothing, Val(N))), nothing))

@adjoint function Base.first(xs::Tuple)
drest = map(_->nothing, tail(xs))
first(xs), Δ -> ((Δ, drest...),)
Expand Down

0 comments on commit 0d5df1b

Please sign in to comment.