private static void Swap(ref MemoryAlignedMatrix A, ref MemoryAlignedMatrix B) { MemoryAlignedMatrix temp = A; A = B; B = temp; }
public static MemoryAlignedMatrix Power(this MemoryAlignedMatrix a, int n) { MemoryAlignedMatrix z = null; MemoryAlignedMatrix result = null; MemoryAlignedMatrix output = new MemoryAlignedMatrix(a.Size); while (n > 0) { if (z == null) { z = a.Copy(); } else { CBLAS.Square(z, output); Swap(ref z, ref output); } int bit = n % 2; n /= 2; if (bit == 1) { if (result == null) { result = z.Copy(); } else { CBLAS.Multiply(result, z, output); Swap(ref result, ref output); } } } return(result); }