First off, this isn’t advanced stuff, conceptually it should be straightforward. I’m almost sure this is just me missing something basic.
So I’m implementing an algorithm which is just a sequence of matrix multiplications. At one point I have S
and A
and I am told to compute K = A * inv(S)
. (Asterisk means regular matrix multiplication). The lore is “don’t compute inverses, solve the linear system”. So I’m trying to obtain K
by solving the following system:
Solve K * S = A
, to obtain K
, given S
and A
.
These things have dimensions:
S (NxN)
K (FxN)
A (FxN)
N > F
I have managed to do this while allocating:
F = 5
N = 8
# this is an exercise, pretend we don't know K
K = rand(Float64, F, N)
# We know S and A:
S = rand(Float64, N, N)
A = K*S
fac = lu(S)
LinearAlgebra.rdiv!(A, fac) # output gets placed into A - weird but ok
A ≈ K # true, works!
Question, how do I make this allocation-free?
I see that lu!
exists, which gave me hope that I could re-use the factorization object, for example by replacing fac = lu(S)
with fac = lu!(fac, S)
. However, fac
is type LU
and the methods of lu!
that take LU
are
[11] lu!(F::LU{<:Any, <:Tridiagonal}, A::Tridiagonal, pivot::Union{NoPivot, RowMaximum}; check, allowsingular)
@ ~/julia-1.11.5/share/julia/stdlib/v1.11/LinearAlgebra/src/lu.jl:580
[12] lu!(F::LU{<:Any, <:Tridiagonal}, A::Tridiagonal; ...)
@ ~/julia-1.11.5/share/julia/stdlib/v1.11/LinearAlgebra/src/lu.jl:580
But my matrix S isn’t tridiagonal…
Thank you.