Help with allocations (variable length least squares)

They can be stack allocated and mutated, for example:

julia> using StaticArrays, BenchmarkTools

julia> function rotate!(v)
         M = MMatrix{2,2,Float64}(0,0,0,0)
         for i in 1:length(v)
            θ = 2π*rand()
            M[1,1] = cos(θ)
            M[1,2] = -sin(θ)
            M[2,1] = sin(θ)
            M[2,2] = cos(θ)
            v[i] = M*v[i]
         end
       end
rotate! (generic function with 2 methods)

julia> v = [ rand(SVector{2,Float64}) for i in 1:10 ];

julia> @btime rotate!($v)
  408.805 ns (0 allocations: 0 bytes)


3 Likes