Skip to content

Commit 8f30e9d

Browse files
namedtuple getfield, for iteration
Co-Authored-By: dhairyagandhi96 <dhairya@juliacomputing.com>
1 parent 16b9aea commit 8f30e9d

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/lib/lib.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ end
105105
@adjoint Core.getfield(xs::NTuple{N,Any}, i::Integer) where N =
106106
(xs[i], Δ -> (ntuple(j -> i == j ? Δ : nothing, Val(N)), nothing))
107107

108+
@adjoint Core.getfield(xs::NamedTuple{K,<:NTuple{N,Any}}, i::Integer) where {K,N} =
109+
(xs[i], Δ -> (NamedTuple{K}(ntuple(j -> i == j ? Δ : nothing, Val(N))), nothing))
110+
108111
@adjoint function Base.first(xs::Tuple)
109112
drest = map(_->nothing, tail(xs))
110113
first(xs), Δ -> ((Δ, drest...),)

0 commit comments

Comments
 (0)