Accord.Tests.Math.JaggedCholeskyDecompositionFTest.InPlaceTest C# (CSharp) Method

InPlaceTest() private method

private InPlaceTest ( ) : void
return void
        public void InPlaceTest()
        {
            float[][] value = // positive-definite
            {
                new float[] {  9, -1,  0,  2, -3 },
                new float[] { -1, 11, -1,  3,  9 },
                new float[] {  0, -1, 15, -2, -2 },
                new float[] {  2,  3, -2, 16,  8 },
                new float[] { -3,  9, -2,  8, 11 },
            };

            float[][] original = value.MemberwiseClone();

            Assert.IsTrue(value.IsSymmetric());

            var chol = new JaggedCholeskyDecompositionF(value, robust: false, inPlace: true);
            float[] diagonal = value.Diagonal();

            // Upper triangular should contain the original matrix (except diagonal)
            for (int i = 1; i < value.Length; i++)
                for (int j = i + 1; j < value.Length; j++)
                    Assert.AreEqual(original[i][j], value[i][j]);

            // Lower triangular should contain the Cholesky factorization
            float[][] expected = 
            {
                new float[] {  3.000f,       0,       0,       0,       0 },
                new float[] { -0.333f,  3.300f,       0,       0,       0 },
                new float[] {  0.000f, -0.303f,  3.861f,       0,       0 },
                new float[] {  0.667f,  0.976f, -0.441f,  3.796f,       0 },
                new float[] { -1.000f,  2.626f, -0.312f,  1.571f,  0.732f },
            };

            float[][] L = chol.LeftTriangularFactor;
            for (int i = 0; i < value.Length; i++)
                for (int j = 0; j <= i; j++)
                    Assert.AreEqual(expected[i][j], value[i][j], 1e-3);
        }