-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
NamedTuple covariance #32825
Comments
See also #24614 😂 I think the main reason invariant named tuples are useful is that a named tuple with The main issue I see with covariance is that a tuple of Int or Missing must have either the type |
In addition to Jeff's great points, I've also been diving a lot into the remaining inconveniences of working w/ With #32448, NamedTuples (and all structs) w/ isbits Union fields will be stored inline in Arrays. With #32699, we actually get into a scenario where you can do a lazy map (a la And honestly, by having a lazy map that can be inferred when collecting, we do away with the main reason I'm aware of for the At this point, I think there's strong reasoning and momentum to not further complicate the data ecosystem by hanging on to DataValues. There are so many great developments going on between machine learning frameworks, core statistics, applied math and optimization techniques, and they've all adopted and moved forward with the I think sometimes we also get really caught up on temporary inconveniences and miss the forest for the trees; Jeff and I sat for maybe 20 minutes at the JuliaCon hackathon and were able to hammer out a bunch of concrete issues to improve various scenarios. I think it'd be much more productive for everyone to highlight the inconveniences and then come together to figure out solutions; having dug so deep into all of this over the last month or two, I really think it was the right choice to go w/ the |
I came to the opposite conclusion by the same reasoning, e.g. using LightQuery: @name
using InteractiveUtils: @code_warntype
unstable() = rand(Bool) ? 1 : 1.0
test1() = (a = unstable(), b = unstable(), c = unstable())
test2() = @name (a = unstable(), b = unstable(), c = unstable())
@code_warntype test1()
@code_warntype test2() |
Although maybe #32699 would solve that? |
Well anyways once #32699 comes out I'll try switching LightQuery over to regular NamedTuples and see what happens to performance |
The "2^N types" is not an inference issue; it's more fundamental. We have no way to efficiently store such a structure. We'd like to keep a bit for each element saying whether it's Int or Missing, but we can't because neither of the types We could fix that by having the outer structure (an array of tuples) store all the tuples inline, with N bits next to each specifying which tuple type it has. But we don't have that implemented, and it doesn't really seem worth it --- we would still only infer an abstract type when you index the array, and code_warntype would still be red. |
That's not a problem for me; I store data column-wise in LightQuery. What is important is to get efficient iterators |
I really think #32699 is the answer here; it should give inference just enough information to realize it can avoid materializing the temporary NamedTuple all together and efficiently store the computed values into output columns directly. |
This might not have been the best choice of word. As Jeff said later, we know how to efficiently store this structure without too much difficulty, the problem is that we can't compute the value of the NamedTuple. |
Right; the problem can be avoided by never materializing the tuples. For example you can return a lazy |
The covariant named tuples came out of me experimenting with a way to write named tuples before NamedTuples came about, and realizing that my version of named tuples didn't suffer from #32699 . I thought it was because of covariance but I guess its just a missing optimization? |
Reopen if no I guess |
Missing case apart, My own case @test NamedTuple{(:a,),Tuple{Int64}} <: NamedTuple{NS,T} where {NS,T<:Tuple}
@test_broken Type{NamedTuple{(:a,),Tuple{Int64}}} <: Type{NamedTuple{NS,T} where {NS,T<:Tuple}} Edited: may be rather due to a |
I thought there was already an issue open for this but I couldn't find it. I don't know if people saw my JuliaCon talk but I implemented covariant namedtuples for LightQuery. If that would be useful, maybe we could get it in Base, and if its not useful, I'd like to understand why, and I can switch LightQuery over to using DataValues and invariant NamedTuples.
The text was updated successfully, but these errors were encountered: