-
Notifications
You must be signed in to change notification settings - Fork 46
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
allocation with v.="x"on SparseArrays #404
Comments
Do note that another solution is The culprit is that broadcast is only for unaliased vector (unalised refers to the left and right-hand side sharing memory, here both matrices are the same, so they naturally share vector) because it may or may not change the structure. using SparseArrays
function f(x, y)
for i in 1:10000
y .= x .* 1.1
x .= y .* (1 / 1.1)
end
x
end
x = spzeros(10)
x[1] = 3
y = copy(x)
@time f(x, y)
@time f(x, y) gives
@ViralBShah we could optimize this for fixed sparse matrices, what do you think? |
I suppose that makes sense. @Wimmerer ? |
I'm not convinced we can't optimize this within the semantics of sparse broadcast. |
So we only trigger a copy if the structure changes or just do it inplace? |
The following code allocates 128 bytes in julia 1.9 & 1.10 (also in previous julia versions). However, when using dense vectors, it doesn't allocate.
Currently the workaround is using
map!(f, v,v)
The text was updated successfully, but these errors were encountered: