-
-
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
Implementation of a merge
function
#186
Comments
Yeah, that would be nice. You can also accomplish this by doing julia> p = ComponentArray(r = ones(N), b = 3 * ones(N))
ComponentVector{Float64}(r = [1.0, 1.0], b = [3.0, 3.0])
julia> p2 = ComponentArray(r = 2 * ones(N))
ComponentVector{Float64}(r = [2.0, 2.0])
julia> ComponentArray(p; p2...)
ComponentVector{Float64}(r = [2.0, 2.0], b = [3.0, 3.0]) |
I don't know that it is especially efficient, though |
The problem with the code that you propose is that it is not compatible with Zygote. Here is a version that works with Zygote: 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 However, here it is assumed that |
see also #69 |
Hey there,
I thought it'd be very cool to have a specialisation of the
merge
function forComponentArray
s, with a similar behaviour as withDictionary
s orNamedTuple
s.For instance, consider
It could be useful to have a similar functionality with
p
andp2
beingComponentArray
s.I am not sure whether this could be efficiently implemented though.
The text was updated successfully, but these errors were encountered: