Accord.Statistics.Distributions.Univariate.KolmogorovSmirnovDistribution.matrixPower C# (CSharp) Method

matrixPower() private static method

Computes matrix power. Used in the Durbin algorithm.
private static matrixPower ( double A, int eA, double V, int &eV, int m, int n, double B ) : void
A double
eA int
V double
eV int
m int
n int
B double
return void
        private static void matrixPower(double[,] A, int eA, double[,] V, ref int eV, int m, int n, double[,] B)
        {
            if (n == 1)
            {
                for (int i = 0; i < m; i++)
                    for (int j = 0; j < m; j++)
                        V[i, j] = A[i, j];
                eV = eA;
                return;
            }

            matrixPower(A, eA, V, ref eV, m, n / 2, B);


            Matrix.Dot(V, V, result: B);

            int eB = 2 * eV;
            if (B[m / 2, m / 2] > 1.0e140)
            {
                for (int i = 0; i < m; i++)
                    for (int j = 0; j < m; j++)
                        B[i, j] *= 1.0e-140;
                eB += 140;
            }

            if (n % 2 == 0)
            {
                for (int i = 0; i < m; i++)
                    for (int j = 0; j < m; j++)
                        V[i, j] = B[i, j];
                eV = eB;
            }
            else
            {
                Matrix.Dot(A, B, result: V);
                eV = eA + eB;
            }

            if (V[m / 2, m / 2] > 1.0e140)
            {
                for (int i = 0; i < m; i++)
                    for (int j = 0; j < m; j++)
                        V[i, j] *= 1.0e-140;
                eV += 140;
            }
        }