Beispiel #1
0
        private 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);
            }
        }
        /// <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];
//			}
            Random r = new 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);
        }
        /// <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];
//			}
            Random r = new 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);
        }
Beispiel #4
0
        [Test] public virtual void SparseVector()
        {
            int n = TesterUtilities.getInt(nmax, r), nu = GetNu(n);
            IElementalAccessVector x = new SparseVector(n);

            repeatedAssembly(x, nu);
        }
Beispiel #5
0
        [Test] public virtual void SparseColumnMatrix()
        {
            int n  = TesterUtilities.getInt(nmax, r),
                m  = TesterUtilities.getInt(mmax, r),
                nu = GetNu(n, m);

            IElementalAccessMatrix A = new SparseColumnMatrix(n, m);

            repeatedAssembly(A, nu);
        }
Beispiel #6
0
        [Test] public virtual void CoordinateTranspose()
        {
            int n  = TesterUtilities.getInt(nmax, r),
                m  = TesterUtilities.getInt(mmax, r),
                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);
            }
        }
Beispiel #7
0
        [Test] public virtual void SparseColumnRowTranspose()
        {
            int n  = TesterUtilities.getInt(nmax, r),
                m  = TesterUtilities.getInt(mmax, r),
                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);
            }
        }
Beispiel #8
0
        private 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);
            Random r = new Random();
            double alpha = r.NextDouble(), beta = r.NextDouble();

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

            checkEqual(z, zd);
        }
Beispiel #9
0
        [Test] public virtual void SparseColumnRowMatrix()
        {
            int n  = TesterUtilities.getInt(nmax, r),
                m  = TesterUtilities.getInt(mmax, r),
                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));
            }
        }
Beispiel #10
0
        [Test] public virtual void SparseRowColumnTransMult()
        {
            int n  = TesterUtilities.getInt(nmax, r),
                m  = TesterUtilities.getInt(mmax, r),
                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);
            }
        }
Beispiel #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];
            Random   r    = new 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);
        }
Beispiel #12
0
        private 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);
            }
        }
Beispiel #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];
            Random   r    = new 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);
        }
Beispiel #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];
//			}
            Random r = new 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);
        }
Beispiel #15
0
 private void check(IElementalAccessMatrix A, double[,] real)
 {
     AreEqual(TesterUtilities.getElMatrix(A), real);
     AreEqual(TesterUtilities.getMatrix(A), real);
     AreEqual(TesterUtilities.getMatrixCopy(A), real);
 }
Beispiel #16
0
 private void rowCheck(IElementalAccessMatrix A, IElementalAccessVector x,
                       IElementalAccessVector y, IElementalAccessVector z, int nu)
 {
     double[,] Ad = TesterUtilities.SetAssembleRowMatrix(A, nu);
     check(A, x, y, z, Ad);
 }
Beispiel #17
0
 private void transColumnCheck(IElementalAccessMatrix A, IElementalAccessVector x,
                               IElementalAccessVector y, IElementalAccessVector z, int nu)
 {
     double[,] Ad = TesterUtilities.setAssembleColumnMatrix(A, nu);
     transCheck(A, x, y, z, Ad);
 }
Beispiel #18
0
        // VECTOR TESTING

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