mathnet-numerics
mathnet-numerics copied to clipboard
Avoidable allocations
While C# is pretty fast at allocations, they can have a GC penalty. Math.NET is generally pretty good at avoiding allocations, but there are a few scenarios that might have slipped through. These are a few I encountered today:
Avoidable allocations
Here I mainly refer to the Double implementations, though the issues may be more general.
DenseVector.InfinityNorm(): avoidable delegate allocations of Math.MaxDenseVector.L2Norm(): avoidable delegate allocationVector.Do*(): scalar operand functions which call out toMapallocate a delegate per callMatrix.DoAdd(), DoSubtract(), DoModulus(), ...: a few scalar operand functions which allocate a delegate per call for use with CommonParallel
Allow reusing allocations
Factorization.DenseLU() doesn't provide a way to input a result matrix, and always does
var factors = (DenseMatrix) matrix.Clone() where matrix is the input matrix and factors is the result of the LU factorization.