コード例 #1
0
        public void SparseSample_ComplexFloat_Identity()
        {
            NumericsConfiguration.NativeProviderPath = @"C:\Program Files (x86)\Extreme Optimization\Numerical Libraries for .NET\bin\Net40";
            NumericsConfiguration.Providers.RegisterSinglePrecisionProvider();
            NumericsConfiguration.AutoLoadNativeProviders = true;
            CoreImplementations <float> .UseNative();

            Console.WriteLine(CoreImplementations <Complex <float> > .LinearAlgebra.Name);

            SparseCompressedColumnMatrix <Complex <float> > matrixA = Matrix.CreateSparse <Complex <float> >(3, 3);

            matrixA.SetValue(new Complex <float>(1, 0), 0, 0);
            matrixA.SetValue(new Complex <float>(1, 0), 1, 1);
            matrixA.SetValue(new Complex <float>(1, 0), 2, 2);
            Vector <Complex <float> > vectorB = Vector.Create(new Complex <float>(1.0f, 0), new Complex <float>(2.0f, 0), new Complex <float>(3.0f, 0));

            IterativeSparseSolver <Complex <float> > solver       = new BiConjugateGradientSolver <Complex <float> >(matrixA);
            DenseVector <Complex <float> >           resultVector = solver.Solve(vectorB);

            Console.WriteLine("Result: {0}", resultVector);
            Console.WriteLine("Solved in {0} iterations.", solver.IterationsNeeded);
            Console.WriteLine("Estimated error: {0}", solver.SolutionReport.Error);

            // With incomplete LU preconditioner
            solver.Preconditioner = new IncompleteLUPreconditioner <Complex <float> >(matrixA);
            resultVector          = solver.Solve(vectorB);

            Console.WriteLine("Result: {0}", resultVector);
            Console.WriteLine("Solved in {0} iterations.", solver.IterationsNeeded);
            Console.WriteLine("Estimated error: {0}", solver.EstimatedError);
        }
コード例 #2
0
        public void ExecuteSample()
        {
            // The line below sets the path where the native assemblies
            // are located. The "XO_LIBRARY_PATH" environment variable
            // points here, too.
            NumericsConfiguration.NativeProviderPath =
                @"C:\Program Files (x86)\Extreme Optimization\Numerical Libraries for .NET\bin\Net40";

            // Register the single precision providers.
            NumericsConfiguration.Providers.RegisterSinglePrecisionProvider();
            NumericsConfiguration.AutoLoadNativeProviders = true;
            CoreImplementations <float> .UseNative();

            // Which provider are we using?
            Console.WriteLine(CoreImplementations <Complex <float> > .LinearAlgebra.Name);

            int N = 228724; // size
            int K = 96;     // non-zeros per column

            // Create some random matrices. Code is below.
            // Use a seed so we can reproduce the same values.
            NumericsConfiguration.DefaultRandomNumberGenerator = new Extreme.Mathematics.Random.MersenneTwister(117);

            var matrixA = CreateSparseRandom(N, K);
            var vectorB = CreateRandom(N);// CreateRandom(N);

            // Now run the solver with and without preconditioner:
            var sw     = Stopwatch.StartNew();
            var solver = new BiConjugateGradientSolver <Complex <float> >(matrixA);

            Console.WriteLine("Starting solve...");
            Vector <Complex <float> > resultVector;

            resultVector = solver.Solve(vectorB);
            sw.Stop();

            Console.WriteLine("Result: {0}", resultVector.GetSlice(0, 10));
            Console.WriteLine("Solved in {0} iterations.", solver.IterationsNeeded);
            Console.WriteLine("Estimated error: {0}", solver.SolutionReport.Error);
            Console.WriteLine("Total time: {0} s", sw.Elapsed.TotalSeconds);

            // With incomplete LU preconditioner
            sw.Restart();
            solver.Preconditioner = new IncompleteLUPreconditioner <Complex <float> >(matrixA);
            resultVector          = solver.Solve(vectorB);
            sw.Stop();

            Console.WriteLine("Result: {0}", resultVector.GetSlice(0, 10));
            Console.WriteLine("Solved in {0} iterations.", solver.IterationsNeeded);
            Console.WriteLine("Estimated error: {0}", solver.EstimatedError);
            Console.WriteLine("Total time: {0} s", sw.Elapsed.TotalSeconds);

            Console.WriteLine("Press any key to exit.");
            Console.ReadLine();
        }