-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include an integer setindex
for NamedTuple
#43155
Comments
Hi, I would like to work on this if no one else is currently on it. That would be my first real contribution to an open source project. |
So my proposed method is something like this: function setindex(nt::NamedTuple{names, T}, v, idx::Int)
NamedTuple(zip(names, setindex(Tuple(nt), v, idx)))
end |
You want to make sure that is type stable. I would use And check what is commonly used for |
The method you suggested unfortunately doesn't work and will return the following:
|
However after some experimentation I noticed this will work: function setindex(nt::NamedTuple{names, T}, val::X, idx::Int) where {names, T, X}
NamedTuple{names}(Base.setindex(Tuple(nt), val, idx))
end This is also an order of magnitude faster. Thanks for the suggestion will update my pull request. |
Yes, that's what I mean ;). Also it shouldnt be "faster" it should be essentially a compile-time operation with no allocations. Anything else shouldnt be merged. |
I'm not sure what you mean by this. |
Allocations that show in benchmarks are heap allocations. Thats what we want to be zero. |
Thanks for that insight and yes indeed benchmark shows 0 heap allocations. |
Hi! I am new to Julia and I want to contribute to the Julia community. I completed the Julia basics course from JuliaAcademy. I am also looking forward to Gsoc'22 with Julia. Can anyone guide on how I can start contributing to the good first issues because as a beginner in Julia they seem pretty overwhelming too. 😅 |
hey I want to contribute to this , could u please assign me |
We don't generally assign issues. Make a PR and we'll review it. |
Also the code from @Xnartharax is pretty much all of it. The real work is writing tests and docs. |
We have both
Symbol
andInt
getindex
for aNamedTuple
, but onlySymbol
setindex
.Is there a reason for this? its seems like we should have both in both cases.
The text was updated successfully, but these errors were encountered: