private static void TestIndefiniteSystem(LinearAlgebraProviderChoice providers)
 {
     TestSettings.RunMultiproviderTest(providers, delegate()
     {
         var comparer             = new MatrixComparer(1E-4);
         double residualTolerance = 1e-8;
         (Matrix A, Vector b, Vector xExpected, IPreconditioner M) = DiagonalIndefinite.BuildIndefiniteSystem(20);
         var minres = new MinRes(A.NumRows, residualTolerance, 0, false, false);
         (IVector xComputed, MinresStatistics stats) = minres.Solve(A, b);
         comparer.AssertEqual(xExpected, xComputed);
     });
 }
Beispiel #2
0
 private static void TestIndefiniteSystem(LinearAlgebraProviderChoice providers)
 {
     TestSettings.RunMultiproviderTest(providers, delegate()
     {
         (Matrix A, Vector b, Vector xExpected, IPreconditioner M) = DiagonalIndefinite.BuildIndefiniteSystem(20);
         var builder = new CGAlgorithm.Builder();
         builder.ResidualTolerance     = 1E-6;
         builder.MaxIterationsProvider = new PercentageMaxIterationsProvider(1.0);
         var cg                    = builder.Build();
         Vector xComputed          = Vector.CreateZero(A.NumRows);
         IterativeStatistics stats = cg.Solve(A, b, xComputed, true);
         Assert.False(comparer.AreEqual(xExpected, xComputed));
     });
 }
        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);
            }
        }
Beispiel #4
0
        public static void PreconditioningIndefinite()
        {
            Console.WriteLine("Dense pos-def system WITHOUT preconditioning:");
            (Matrix A, Vector b, Vector xExpected, IPreconditioner M) = DiagonalIndefinite.BuildIndefiniteSystem(2000);
            var minres = new MinRes(A.NumRows, 1e-10, 0, true, false);

            // Without preconditioning
            (IVector xSimple, MinresStatistics statsSimple) = minres.Solve(A, b);
            Console.Write(statsSimple);
            if (xSimple != null)
            {
                CheckSolution(xExpected, xSimple);
            }
            Console.WriteLine();

            // With preconditioning
            (IVector xPrec, MinresStatistics statsPrec) = minres.Solve(A, b, M);
            Console.Write(statsPrec);
            if (xPrec != null)
            {
                CheckSolution(xExpected, xPrec);
            }
            Console.WriteLine();
        }