-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
[WIP] Merge ComponentVectors #217
base: main
Are you sure you want to change the base?
Conversation
This PR will break precompilation. Working on using Macros instead of the Eval (bad idea) |
I think it's resolved now. |
I'm going to go ahead and reopen this because I think it will be useful to have. If you get a chance to change it and write some tests for it, I'd appreciate it. If not, I can do it at some point hopefully soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to have this in as
Base.merge(ca::ComponentVector) = ca
Base.merge(ca1::ComponentVector, ca2::ComponentVector) = ComponentVector(ca2; ca1...)
Base.merge(ca1::ComponentVector, ca2::ComponentVector, others...) = merge(merge(ca1, ca2), others...)
Because the ComponentVector(ca2; ca1...) syntax can already perform the merge via destructuring and splatting ca1.
Codecov Report
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. @@ Coverage Diff @@
## main #217 +/- ##
==========================================
- Coverage 72.75% 71.06% -1.70%
==========================================
Files 20 21 +1
Lines 690 698 +8
==========================================
- Hits 502 496 -6
- Misses 188 202 +14
... and 7 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more 📢 Have feedback on the report? Share it here. |
The whole point was to make it differentiable via ChainRules, though this isn't. A solution exists for making it work with ChainRules, however, I think focusing on #207 is best. |
Last two commits added type promotion. |
Ah, I see. Yeah, we might want to make this work with |
I think something similar to what @vboussange did could work: import Base
function Base.merge(ca::ComponentArray{T}, ca2::ComponentArray{T}) where T
ax = getaxes(ca)
ax2 = getaxes(ca2)
vks = valkeys(ax[1])
vks2 = valkeys(ax2[1])
_p = Vector{T}()
for vk in vks
if vk in vks2
_p = vcat(_p, ca2[vk])
else
_p = vcat(_p, ca[vk])
end
end
ComponentArray(_p, ax)
end Though this one implies that |
The last commit has an example that might be expanded on. Though it's a bit convoluted, it does work. |
Is this still necessary for getting Zygote to work with ComponentArrays sensu #207? |
Issue #186
Implemented
merge
on 2 (or more)ComponentVector
s, similar tomerge
onNamedTuple
s orDict
s. With docs.