Ejemplo n.º 1
0
        private static void TestConversionFullToSkyline()
        {
            var matrices = new List <double[, ]>
            {
                DiagonalIndefinite.BuildeIndefiniteMatrix(20), GlobalMatrixAssembly.GlobalMatrix, SparsePosDef10by10.Matrix,
                SparseSymm5by5.Matrix, SymmPosDef10by10.Matrix, SymmSingular10by10.Matrix
            };

            foreach (double[,] matrix in matrices)
            {
                var full             = Matrix.CreateFromArray(matrix);
                var skylineFromArray = SkylineMatrix.CreateFromArray(matrix);
                var skylineFromFull  = SkylineMatrix.CreateFromMatrix(full);
                comparer.AssertEqual(full, skylineFromArray);
                comparer.AssertEqual(full, skylineFromFull);
            }
        }
Ejemplo n.º 2
0
        private static void TestGetSubmatrix()
        {
            // These are useful for debugging
            //string outputPath = @"C:\Users\Serafeim\Desktop\output.txt";
            //var writer = new LinearAlgebra.Output.FullMatrixWriter();

            var matrix = Matrix.CreateFromArray(
                MultiDiagonalMatrices.CreateSymmetricPosDef(100, new int[] { 2, 4, 8, 16, 32, 64 }));
            var matrixSky = SkylineMatrix.CreateFromMatrix(matrix);

            var indices     = new int[] { 0, 2, 4, 6, 12, 24, 32, 50, 64, 80 };
            var indicesPerm = new int[] { 32, 80, 64, 0, 12, 24, 6, 50, 4, 2 };

            int[] rowIndices = indicesPerm;
            var   colIndices = new int[] { 90, 10, 20, 60, 40, 50, 0, 70, 80, 30 };

            Matrix        subMatrixFull = matrixSky.GetSubmatrixSymmetricFull(indices);
            SkylineMatrix subMatrixSky  = matrixSky.GetSubmatrixSymmetricSkyline(indices);
            //writer.WriteToFile(subMatrixSky, outputPath, true);
            CscMatrix subMatrixCsc = matrixSky.GetSubmatrixCsc(indices, indices);

            Matrix        subMatrixPermFull = matrixSky.GetSubmatrixSymmetricFull(indicesPerm);
            SkylineMatrix subMatrixPermSky  = matrixSky.GetSubmatrixSymmetricSkyline(indicesPerm);
            CscMatrix     subMatrixPermCsc  = matrixSky.GetSubmatrixCsc(indicesPerm, indicesPerm);

            CscMatrix subMatrixRectCsc = matrixSky.GetSubmatrixCsc(rowIndices, colIndices);

            Matrix subMatrixExpected = matrix.GetSubmatrix(indices, indices);

            //writer.WriteToFile(subMatrixExpected, outputPath, true);
            Assert.True(subMatrixExpected.Equals(subMatrixFull));
            Assert.True(subMatrixExpected.Equals(subMatrixSky));
            Assert.True(subMatrixExpected.Equals(subMatrixCsc));

            Matrix subMatrixPermExpected = matrix.GetSubmatrix(indicesPerm, indicesPerm);

            Assert.True(subMatrixPermExpected.Equals(subMatrixPermFull));
            Assert.True(subMatrixPermExpected.Equals(subMatrixPermSky));
            Assert.True(subMatrixPermExpected.Equals(subMatrixPermCsc));

            Matrix subMatrixRectExpected = matrix.GetSubmatrix(rowIndices, colIndices);

            Assert.True(subMatrixRectExpected.Equals(subMatrixRectCsc));
        }