# Operate only on a few components of a static vector

**URL:** <https://discourse.julialang.org/t/operate-only-on-a-few-components-of-a-static-vector/62409>\
**Category:** General Usage\
**Tags:** staticarrays\
**Created:** [June 4, 2021, 10:03pm UTC](https://discourse.julialang.org/t/operate-only-on-a-few-components-of-a-static-vector/62409 "2021-06-04T22:03:01Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [June 4, 2021, 11:33pm UTC](https://discourse.julialang.org/t/operate-only-on-a-few-components-of-a-static-vector/62409/11 "2021-06-04T23:33:32Z")

</div>

> [@SparseMatrix or SArray, MArray?](https://discourse.julialang.org/t/sparsematrix-or-sarray-marray/61401/5):
>
> For convenience, yes, but this is what I mean: using StaticArrays, BenchmarkTools, Setfield function mut!(A) A .= A .+ 1 end Base.setindex!(m::SMatrix,value,i,j) = @set! m[i,j] = value A1 = rand(3,3) A2 = rand(MMatrix{3,3,Float64}) A3 = rand(SMatrix{3,3,Float64}) @btime mut!($A1) @btime mut!($A2) @btime mut!($A3) Results: 14.548 ns (0 allocations: 0 bytes) 4.733 ns (0 allocations: 0 bytes) 1.791 ns (0 allocations: 0 bytes) This actually makes me wonder how and why MMatrix …

Look at this. For longer vectors that changes? Is that the point?

---

_[View the full topic](https://discourse.julialang.org/t/operate-only-on-a-few-components-of-a-static-vector/62409)._
