-
Notifications
You must be signed in to change notification settings - Fork 41
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
setindex and promotion #131
Comments
I might have missed this because it's not really about |
Just stumbled upon this issue and the connected issues #182 and PR #184 because I experienced a problem today which I think is similar: julia> mutable struct A
id::Int
end
julia> sa = StructArray{A}(undef, 0)
0-element StructArray(::Vector{Int64}) with eltype A
julia> push!(sa, A(1))
1-element StructArray(::Vector{Int64}) with eltype A:
A(1)
## getting
julia> sa[1]
A(1)
julia> sa[1].id
1
julia> view(sa, 1).id
0-dimensional view(::Vector{Int64}, 1) with eltype Int64:
1
## setting
julia> sa[1].id = 2 # fails silently
2
julia> sa
1-element StructArray(::Vector{Int64}) with eltype A:
A(1)
julia> sa.id[1] = 2 # succeeds
2
julia> sa
1-element StructArray(::Vector{Int64}) with eltype A:
A(2) Am I right in assuming that these problems are connected? If not, please correct me if I'm wrong. :) For comparison, here's how it works in a vector of structs: julia> a = [A(1)]
1-element Vector{A}:
A(1)
## getting
julia> a[1]
A(1)
julia> a[1].id
1
## setting
julia> a[1].id = 2 # succeeds
2
julia> a
1-element Vector{A}:
A(2) I had assumed that |
That's actually a separate issue, as the structs are not actually stored (only their fields are), so Maybe that behavior should be documented more thoroughly (documentation PRs welcome!) |
I did not know that! Thanks for the answer. :) I will have to look for other ways around this then, maybe |
Fixes #131 Closes #184 Co-authored-by: Gustavo Goretkin <[email protected]>
This is needed for StructArrays v0.6.8 https://github.com/JuliaArrays/StructArrays.jl/releases/tag/v0.6.8 See JuliaArrays/StructArrays.jl#131 JuliaArrays/StructArrays.jl#216 It's not clear to me whether the behaviour of StructArrays.jl is now correct (so this is a PALEOboxes.jl fix that used to not matter) or whether this is a workaround for a newly introduced StructArrays.jl issue
Compare that with the behavior of normal arrays:
I think
StructArray
should replicate the behavior of normal arrays, and promote the value being assigned.The text was updated successfully, but these errors were encountered: