# Sparsevector .+=

**URL:** <https://discourse.julialang.org/t/sparsevector/8661>\
**Category:** General Usage\
**Created:** [January 29, 2018, 12:48am UTC](https://discourse.julialang.org/t/sparsevector/8661 "2018-01-29T00:48:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![augustinyiptong](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/augustinyiptong/32/1785_2.png) [@augustinyiptong](https://discourse.julialang.org/u/augustinyiptong)\
**Post date:** [January 29, 2018, 12:48am UTC](https://discourse.julialang.org/t/sparsevector/8661/1 "2018-01-29T00:48:52Z")

</div>

> A = sparsevec([0, 0, 1, 1])  
> B = sparsevec([1, 1, 0, 0])  
> A .+= B  
> full(A)

gives

> 4-element Array{Int64,1}:  
> 1  
> 1  
> 1  
> 0

which doesnt look right?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 29, 2018, 1:14am UTC](https://discourse.julialang.org/t/sparsevector/8661/2 "2018-01-29T01:14:56Z")

</div>

In general you cannot guarantee that the sum (or broadcasted function) of 2 (or more) sparse vectors is sparse.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [January 29, 2018, 1:26am UTC](https://discourse.julialang.org/t/sparsevector/8661/3 "2018-01-29T01:26:15Z")

</div>

This is a really bad bug that we need to fix: [https://github.com/JuliaLang/julia/issues/21693](https://github.com/JuliaLang/julia/issues/21693).

The problem is that you’re effectively doing `A .= A .+ B` — both reading from and mutating `A` at the same time. We simply don’t support that at the moment, but it needs to be an error.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [January 29, 2018, 9:04am UTC](https://discourse.julialang.org/t/sparsevector/8661/4 "2018-01-29T09:04:23Z")

</div>

> [@mbauman](#):
>
> We simply don’t support that at the moment, but it needs to be an error.

I think in the issue it’s not decided yet whether it should be an error or not. There are strong arguments (IMHO) to make this work, doing a copy under the hood if needed to ensure that this generic syntax works for sparse arrays.
