Skip to content
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

zeros does not allocate memory for each instance. #767

Closed
GiggleLiu opened this issue Apr 15, 2020 · 2 comments
Closed

zeros does not allocate memory for each instance. #767

GiggleLiu opened this issue Apr 15, 2020 · 2 comments
Labels
fix-in-base Fix needs some work in Base question

Comments

@GiggleLiu
Copy link

The memory is shared. Is it expected or a bug?

julia> vl = zeros(MVector{3, Float64}, 3)
3-element Array{MArray{Tuple{3},Float64,1,3},1}:
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]

julia> vl[1] .= 2
3-element MArray{Tuple{3},Float64,1,3} with indices SOneTo(3):
 v2.0l
 2.0
 2.0

julia> vl
3-element Array{MArray{Tuple{3},Float64,1,3},1}:
 [2.0, 2.0, 2.0]
 [2.0, 2.0, 2.0]
 [2.0, 2.0, 2.0]
@tkf
Copy link
Member

tkf commented Apr 15, 2020

Yeah, it is "expected" given how zeros work. Though I agree it's counter-intuitive.

I think this is more like a problem in Base.zeros: JuliaLang/julia#29168

@c42f c42f added question fix-in-base Fix needs some work in Base labels Apr 16, 2020
@c42f
Copy link
Member

c42f commented Apr 16, 2020

Great, thanks for that cross-ref to the Base issue, this is definitely an issue which would need to be resolved in Base.

zeros(MVector{3, Float64}, 3) just calls the Base implementation of zeros and I don't think it would be helpful for StaticArrays to depart from how other mutable types are treated when passed to zeros.

@c42f c42f closed this as completed Apr 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix-in-base Fix needs some work in Base question
Projects
None yet
Development

No branches or pull requests

3 participants