Open alblaz opened 7 months ago
function ldiv_for_generated!(C, A, B) # C=A\B. Called from generated code
F = lu!(A) # This allocation is unavoidable, due to the interface of LinearAlgebra
ldiv!(F, B) # Result stored in B
if (pointer_from_objref(C) != pointer_from_objref(B)) # Aliasing allowed
copyto!(C, B)
end
return C
end
The array version has an allocation due to BLAS. This can be removed by using LinearSolve.jl. But note that there are sub-allocations in that not tracked by GC because it's in the BLAS workspace.
The MMatrix version is using GenericSchur.jl. You can see the extra allocations here:
https://github.com/RalphAS/GenericSchur.jl/blob/master/src/balance.jl#L45-L49
It would be nice to improve the alloc_mem interface to allocate those and then extend the GenericSchur.jl balance! function so that they can be passed in. If anyone has the time to do that then this is a nice straightforward issue to improve performance a bit.
The snippet below shows that for small matrices using
MMatrix
as argument ofexponential!
is faster than using a regularMatrix
. However theMMatrix
allocates more. Is this the expected behaviour?Matrix 0.000037 seconds (1 allocation: 80 bytes) MMatrix 0.000006 seconds (6 allocations: 416 bytes)