mathnet-numerics
mathnet-numerics copied to clipboard
Copy-avoidance optimizations on Combinatorics
Support [ReadOnly]Span, because unlike arrays, it cannot be cast to IEnumerable without an extra copy. Memory has a Span property that does not copy so no need to add a version for it. Note that Span only support .Net Core 2.1 and later versions on this line. Framework, Standard (except the rarely used Standard 2.1) and UWP don't support Span.
Extend arrays to I[ReadOnly]List. For arrays this interface behaves identically, but it can also support other implementations without an extra copy. For example, SelectPermutationInplace could only perform on the full range of an array - it was not possible to permute only a segment of the array. Now you can create an ArraySegment, which implements IList, and pass it to SelectPermutationInplace. Only the range specified when creating the ArraySegment will be permuted. You can also pass ArraySegment to other similar functions. This is more efficient than Skip-Take in that it does not copy.
Add an InPlace version of SelectVariation to save a copy if the caller allows modifications on the input data.