Ejemplo n.º 1
0
Archivo: LU.cs Proyecto: say1981/Rawr
        private void TestUpdateFSolveSize(int size)
        {
            Random rnd = new Random();

            double[] B = new double[size * size];
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    B[i * size + j] = rnd.NextDouble();
                }
            }
            double[] B0 = (double[])B.Clone();
            int      c  = rnd.Next(size);

            double[] newB = new double[size];
            double[] tmp  = new double[size];
            for (int i = 0; i < size; i++)
            {
                newB[i]         = rnd.NextDouble();
                B[i * size + c] = newB[i];
            }
            double[] x = new double[size];
            for (int i = 0; i < size; i++)
            {
                x[i] = rnd.NextDouble();
            }
            double[] b = new double[size];
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    b[i] += B[i * size + j] * x[j];
                }
            }
            Array.Copy(B0, Rawr.Mage.LU._U, size * size);
            Mage.LU lu = new Rawr.Mage.LU(size);
            fixed(double *U = Rawr.Mage.LU._U, sL = Rawr.Mage.LU.sparseL, column = Rawr.Mage.LU.column, column2 = Rawr.Mage.LU.column2)
            fixed(int *P = Rawr.Mage.LU._P, Q = Rawr.Mage.LU._Q, LJ = Rawr.Mage.LU._LJ, sLI = Rawr.Mage.LU.sparseLI, sLstart = Rawr.Mage.LU.sparseLstart)
            {
                lu.BeginUnsafe(U, sL, P, Q, LJ, sLI, sLstart, column, column2);
                lu.Decompose();
                unsafe
                {
                    fixed(double *nb = newB, t = tmp, _b = b)
                    {
                        lu.FSolveL(nb, t);
                        double pivot;

                        lu.Update(t, c, out pivot);
                        lu.FSolve(_b);
                    }
                }
            }
            for (int i = 0; i < size; i++)
            {
                Assert.AreEqual(x[i], b[i], 0.000001, "Size = " + size);
            }
        }
Ejemplo n.º 2
0
Archivo: LU.cs Proyecto: say1981/Rawr
        private void TestFSolveSize(int size)
        {
            Random rnd = new Random();

            double[] B = new double[size * size];
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    B[i * size + j] = rnd.NextDouble();
                }
            }
            double[] x = new double[size];
            for (int i = 0; i < size; i++)
            {
                x[i] = rnd.NextDouble();
            }
            double[] b = new double[size];
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    b[i] += B[i * size + j] * x[j];
                }
            }
            Array.Copy(B, Rawr.Mage.LU._U, size * size);
            Mage.LU lu = new Rawr.Mage.LU(size);
            fixed(double *U = Rawr.Mage.LU._U, sL = Rawr.Mage.LU.sparseL, column = Rawr.Mage.LU.column, column2 = Rawr.Mage.LU.column2)
            fixed(int *P = Rawr.Mage.LU._P, Q = Rawr.Mage.LU._Q, LJ = Rawr.Mage.LU._LJ, sLI = Rawr.Mage.LU.sparseLI, sLstart = Rawr.Mage.LU.sparseLstart)
            {
                lu.BeginUnsafe(U, sL, P, Q, LJ, sLI, sLstart, column, column2);
                lu.Decompose();
                unsafe
                {
                    fixed(double *_b = b)
                    {
                        lu.FSolve(_b);
                    }
                }
            }
            for (int i = 0; i < size; i++)
            {
                Assert.AreEqual(x[i], b[i], 0.000001, "Size = " + size);
            }
        }