Closed slwu89 closed 1 year ago
It's not a Dict
thing, it's just because indexing into a ComponentArray
(or any array) creates a new array. So doing
cells_state[Symbol(1)][1] = -500.0
is first creating a new array with cells_state[Symbol(1)]
and then setting the first element to -500.0
. I think the thing that sometimes catches people off guard about this with ComponentArrays is that if you were doing this with "dot" property access, it would work as expected. So for example,
julia> x = ComponentArray(a = cell_ic, b = cell_ic, c = cell_ic);
julia> x.a[1] = -500.0;
julia> x
ComponentVector{Float64}(a = [-500.0, 1.0, 20.0], b = [20.0, 1.0, 20.0], c = [20.0, 1.0, 20.0])
This is intended behavior, although admittedly it's a little counterintuitive at first. The main issue is that getproperty
purposely works differently than getindex
for ComponentArrays. It used to be the case that they were the same, but it got confusing that getindex
worked differently for ComponentArrays than other array types because it created a view
instead of a new array.
Thanks @jonniedie, I see now that it's explained in the Indexing Behavior section of the docs. Feel free to close!
Hi,
It appears that ComponentArrays built from Dicts are not mutable, see my example below. Is this intended behavior?
I'm on package version ComponentArrays v0.13.9. Thanks!