Esempio n. 1
0
        private static void repeatedAssembly(IElementalAccessMatrix A, int nu)
        {
            for (int i = 0; i < repeat; ++i)
            {
                check(A, TesterUtilities.SetAssembleRowMatrix(A, nu));
                Blas.Default.Zero(A);

                check(A, TesterUtilities.setsAssembleRowMatrix(A, nu));
                Blas.Default.Zero(A);

                check(A, TesterUtilities.AddAssembleRowMatrix(A, nu));
                Blas.Default.Zero(A);

                check(A, TesterUtilities.addsAssembleRowMatrix(A, nu));
                Blas.Default.Zero(A);

                check(A, TesterUtilities.setAssembleColumnMatrix(A, nu));
                Blas.Default.Zero(A);

                check(A, TesterUtilities.setsAssembleColumnMatrix(A, nu));
                Blas.Default.Zero(A);

                check(A, TesterUtilities.addAssembleColumnMatrix(A, nu));
                Blas.Default.Zero(A);

                check(A, TesterUtilities.addsAssembleColumnMatrix(A, nu));
                Blas.Default.Zero(A);
            }
        }
Esempio n. 2
0
        /// <summary> Column-wise assembly using set</summary>
        /// <param name="nu">Maximum bandwidth on each column
        /// </param>
        /// <returns> Dense representation (not a direct copy)
        /// </returns>
        public static double[,] setAssembleColumnMatrix(IElementalAccessMatrix A, int nu)
        {
            int n = A.RowCount, m = A.ColumnCount;

            double[,] data = new double[n, m];
            //			for (int i = 0; i < n; i++)
            //			{
            //				data[i] = new double[m];
            //			}
            System.Random r = new System.Random();

            // Construct the matrix
            for (int i = 0; i < m; ++i)
            {
                for (int j = 0; j < nu; ++j)
                {
                    int    ind   = TesterUtilities.getInt(n, r);
                    double entry = r.NextDouble();
                    data[ind, i] = entry;
                    A.SetValue(ind, i, entry);
                }
            }

            return(data);
        }
Esempio n. 3
0
        /// <summary> Column-wise assembly using setValues</summary>
        /// <param name="nu">Maximum bandwidth on each column
        /// </param>
        /// <returns> Dense representation (not a direct copy)
        /// </returns>
        public static double[,] setsAssembleColumnMatrix(IElementalAccessMatrix A, int nu)
        {
            int n = A.RowCount, m = A.ColumnCount;

            double[,] data = new double[n, m];
            //			for (int i = 0; i < n; i++)
            //			{
            //				data[i] = new double[m];
            //			}
            System.Random r = new System.Random();

            for (int i = 0; i < m; ++i)
            {
                int[] row = TesterUtilities.getIntArray(nu, r), col = TesterUtilities.getIntArray(m, r);
                double[,] entry = TesterUtilities.getDoubleArray(row.Length, col.Length, r);
                for (int ii = 0; ii < row.Length; ++ii)
                {
                    for (int jj = 0; jj < col.Length; ++jj)
                    {
                        data[row[ii], col[jj]] = entry[ii, jj];
                    }
                }
                A.SetValues(row, col, entry);
            }

            return(data);
        }
Esempio n. 4
0
        public virtual void SparseVector()
        {
            int n = TesterUtilities.getInt(nmax, _random), nu = GetNu(n);
            IElementalAccessVector x = new SparseVector(n);

            repeatedAssembly(x, nu);
        }
Esempio n. 5
0
        /// <remarks>"This test been excluded from test fixture by Igor Sukhov on 17.10.2007"</remarks>
        //[TestMethod]
        public virtual void CoordinateMatrix()
        {
            int n  = TesterUtilities.getInt(nmax, _random),
                m  = TesterUtilities.getInt(mmax, _random),
                nu = GetNu(n, m);

            IElementalAccessMatrix A = new CoordinateMatrix(n, m, nu);

            repeatedAssembly(A, nu);
        }
Esempio n. 6
0
        /// <remarks>"This test been excluded from test fixture by Igor Sukhov on 17.10.2007"</remarks>
        //[TestMethod]
        public virtual void CoordinateTranspose()
        {
            int n  = TesterUtilities.getInt(nmax, _random),
                m  = TesterUtilities.getInt(mmax, _random),
                nu = GetNu(n, m);

            for (int i = 0; i < repeat; ++i)
            {
                IElementalAccessMatrix A = new CoordinateMatrix(n, m);
                double[,] Am = TesterUtilities.SetAssembleRowMatrix(A, nu);
                TransposeCheck(A, Am);
            }
        }
Esempio n. 7
0
        /// <remarks>"This test been excluded from test fixture by Igor Sukhov on 17.10.2007"</remarks>
        //[TestMethod]
        public virtual void SparseColumnRowTranspose()
        {
            int n  = TesterUtilities.getInt(nmax, _random),
                m  = TesterUtilities.getInt(mmax, _random),
                nu = GetNu(n, m);

            for (int i = 0; i < repeat; ++i)
            {
                IElementalAccessMatrix A = new SparseColumnRowMatrix(n, m, nu);
                double[,] Am = TesterUtilities.setAssembleColumnMatrix(A, nu);
                TransposeCheck(A, Am);
            }
        }
Esempio n. 8
0
        private static void transCheck(IElementalAccessMatrix A, IElementalAccessVector x,
                                       IElementalAccessVector y, IElementalAccessVector z, double[,] Ad)
        {
            double[] xd = TesterUtilities.setAssembleVector(x),
            yd = TesterUtilities.setAssembleVector(y),
            zd = TesterUtilities.setAssembleVector(z);
            System.Random random = new System.Random();
            double        alpha = random.NextDouble(), beta = random.NextDouble();

            Blas.Default.TransMultAdd(alpha, A, x, beta, y, z);
            transMultAdd(alpha, Ad, xd, beta, yd, zd);

            checkEqual(z, zd);
        }
Esempio n. 9
0
        /// <remarks>"This test been excluded from test fixture by Igor Sukhov on 17.10.2007"</remarks>
        //[TestMethod]
        public virtual void SparseColumnRowMatrix()
        {
            int n  = TesterUtilities.getInt(nmax, _random),
                m  = TesterUtilities.getInt(mmax, _random),
                nu = GetNu(n, m);

            for (int i = 0; i < 10; ++i)
            {
                IElementalAccessMatrix A = new SparseColumnRowMatrix(n, m, nu);
                check(A, TesterUtilities.setAssembleColumnMatrix(A, nu));

                A = new SparseColumnRowMatrix(n, m, nu);
                check(A, TesterUtilities.addAssembleColumnMatrix(A, nu));
            }
        }
Esempio n. 10
0
        public virtual void SparseRowColumnTransMult()
        {
            int n  = TesterUtilities.getInt(nmax, _random),
                m  = TesterUtilities.getInt(mmax, _random),
                nu = GetNu(n, m);

            for (int i = 0; i < repeat; ++i)
            {
                IElementalAccessMatrix A = new SparseRowColumnMatrix(n, m, nu);
                IElementalAccessVector x = new DenseVector(n),
                                       y = new DenseVector(m),
                                       z = new DenseVector(m);

                transRowCheck(A, x, y, z, nu);
            }
        }
Esempio n. 11
0
        /// <summary> Assembly using setValues</summary>
        /// <param name="nu">Maximum number of entries
        /// </param>
        /// <returns> Dense representation (not a direct copy)
        /// </returns>
        public static double[] setsAssembleVector(IElementalAccessVector x, int nu)
        {
            int n = x.Length;

            double[]      data = new double[n];
            System.Random r    = new System.Random();

            int[]    ind = TesterUtilities.getIntArray(nu, r);
            double[] arr = TesterUtilities.getDoubleArray(ind.Length, r);
            for (int i = 0; i < ind.Length; ++i)
            {
                data[ind[i]] = arr[i];
            }
            x.SetValues(ind, arr);
            return(data);
        }
Esempio n. 12
0
        private static void repeatedAssembly(IElementalAccessVector x, int nu)
        {
            for (int i = 0; i < repeat; ++i)
            {
                Check(x, TesterUtilities.setAssembleVector(x, nu));
                Blas.Default.Zero(x);

                Check(x, TesterUtilities.setsAssembleVector(x, nu));
                Blas.Default.Zero(x);

                Check(x, TesterUtilities.addAssembleVector(x, nu));
                Blas.Default.Zero(x);

                Check(x, TesterUtilities.addsAssembleVector(x, nu));
                Blas.Default.Zero(x);
            }
        }
Esempio n. 13
0
        /// <summary> Assembly using setValue</summary>
        /// <param name="nu">Maximum number of entries
        /// </param>
        /// <returns> Dense representation (not a direct copy)
        /// </returns>
        public static double[] setAssembleVector(IElementalAccessVector x, int nu)
        {
            int n = x.Length;

            double[]      data = new double[n];
            System.Random r    = new System.Random();

            for (int i = 0; i < nu; ++i)
            {
                int    ind   = TesterUtilities.getInt(n, r);
                double entry = r.NextDouble();
                data[ind] = entry;
                x.SetValue(ind, entry);
            }

            return(data);
        }
Esempio n. 14
0
        /// <summary> Row-wise assembly using add</summary>
        /// <param name="nu">Maximum bandwidth on each row
        /// </param>
        /// <returns> Dense representation (not a direct copy)
        /// </returns>
        public static double[,] AddAssembleRowMatrix(IElementalAccessMatrix A, int nu)
        {
            int n = A.RowCount, m = A.ColumnCount;

            double[,] data = new double[n, m];
            //			for (int i = 0; i < n; i++)
            //			{
            //				data[i] = new double[m];
            //			}
            System.Random r = new System.Random();

            for (int i = 0; i < n; ++i)
            {
                for (int j = 0; j < nu; ++j)
                {
                    int    ind   = TesterUtilities.getInt(m, r);
                    double entry = r.NextDouble();
                    data[i, ind] += entry;
                    A.AddValue(i, ind, entry);
                }
            }

            return(data);
        }
Esempio n. 15
0
 private static void check(IElementalAccessMatrix A, double[,] real)
 {
     AreEqual(TesterUtilities.getElMatrix(A), real);
     AreEqual(TesterUtilities.getMatrix(A), real);
     AreEqual(TesterUtilities.getMatrixCopy(A), real);
 }
Esempio n. 16
0
 private static void rowCheck(IElementalAccessMatrix A, IElementalAccessVector x,
                              IElementalAccessVector y, IElementalAccessVector z, int nu)
 {
     double[,] Ad = TesterUtilities.SetAssembleRowMatrix(A, nu);
     check(A, x, y, z, Ad);
 }
Esempio n. 17
0
 private static void transColumnCheck(IElementalAccessMatrix A, IElementalAccessVector x,
                                      IElementalAccessVector y, IElementalAccessVector z, int nu)
 {
     double[,] Ad = TesterUtilities.setAssembleColumnMatrix(A, nu);
     transCheck(A, x, y, z, Ad);
 }
Esempio n. 18
0
        // VECTOR TESTING

        private static int GetNu(int n)
        {
            return(Math.Min(n, TesterUtilities.getInt(numax, _random)));
        }
Esempio n. 19
0
 private static void Check(IElementalAccessVector x, double[] real)
 {
     AreEqual(TesterUtilities.getElVector(x), real);
     AreEqual(TesterUtilities.getVector(x), real);
     AreEqual(TesterUtilities.getVectorCopy(x), real);
 }