# Static matrix equation solve in-place?

I’m using static arrays to solve a 3x3 matrix equation that has to be solved repeatedly. Is there a function for solving these equations in place with static arrays (`SMatrix`, `SVector`)? I see all the in-place BLAS routines, but I’m not sure if that will defeat the purpose of using static arrays. So far, `A\b` is considerably faster without decomposing the matrix first for this small system.

I think what you want is `ldiv!`

I gave that a try and got

``````julia> ldiv!(A, b)
ERROR: MethodError: no method matching ldiv!(::SArray{Tuple{3,3},Float64,2,9}, ::MArray{Tuple{3},Float64,1,3})
``````

The docs for `ldiv!` also say " The argument `A` should not be a matrix," so I’m unsure about applicability to an unfactorized static matrix.

If the arrays are static, what’s the purpose of the in-place solve? I believe StaticArrays have custom methods for 3x3 solves that do not allocate anything?

1 Like

Is that the case? I could be confused, but does repeated execution of `x = A\b` somehow compile to an in-place operation with `x`? How can there be zero allocation for the result of `A\b`?

The cool thing with `StaticArray`s is that non-inplace methods don’t have to allocate (on the heap) since you know exactly how much memory it will need.

2 Likes

Ok, so there is no reason to fret about where the result of `A\b` goes, because it’s basically just a tuple and will not cause any slowdown?

3 Likes

Right.

1 Like