Closed
Description
Here's a version of this which doesn't mutate an array, hence works with Zygote:
function _namedtuple(x::ComponentVector)
NamedTuple{keys(x)}(map(valkeys(x)) do key
_namedtuple(getproperty(x, key))
end)
end
And a test which otherwise fails with the latest release version:
@test ComponentArray(x=4,) == Zygote.gradient(ComponentArray(x=2,)) do c
(;c...,).x^2
end[1]
Wanted to just suggest this here rather than PR since there's some stuff that function is doing (or seemed to before comments) that I wasn't sure about. If this is good, please feel free to commit directly.
Metadata
Metadata
Assignees
Labels
No labels