Пример #1
0
        public static SparseMatrix SparseMatrix(int rows, int columns, double density, bool symmetric)
        {
            if (symmetric)
            {
                return(CreateSparse.RandomSymmetric(rows, density));
            }

            return(CreateSparse.Random(rows, columns, density));
        }
Пример #2
0
        public static IStorageAdapter CreateRandom(int rowCount, int columnCount,
                                                   double density, bool symmetric)
        {
            var A = symmetric ? CreateSparse.RandomSymmetric(rowCount, density) :
                    CreateSparse.Random(rowCount, columnCount, density);

            var norms = ToComplexArray((2 * A.RowNorms(1)).ToArray());

            A.FastAddDiagonalMatrix(norms, A);

            return(new SparseStorageAdapter(A));
        }
Пример #3
0
        public void TestAddDiagonalMatrixNew()
        {
            var diag = DenseVector.Create(10, 1.0);

            var A = CreateSparse.Random(10, 10, 0.8);

            A.FastLowerTriangle();
            A.SetDiagonal(diag);

            var empty = CreateSparse.Zeros(A.RowCount, A.ColumnCount, A.NonZerosCount);

            // Add diagonal and save to new matrix.
            A.FastAddDiagonalMatrix(diag.Negate().ToArray(), empty);

            var d = empty.FastDiagonal();

            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(d[i], 0.0);
            }
        }
Пример #4
0
        /// <summary>
        /// Setup test matrices.
        /// </summary>
        private static void SetupMatrices()
        {
            var A55 = CreateSparse.Random(5, 5, 0.5);
            var A57 = CreateSparse.Random(5, 7, 0.5);
            var A75 = CreateSparse.Random(7, 5, 0.5);

            var B55 = CreateSparse.Random(5, 5, 0.5);
            var B57 = CreateSparse.Random(5, 7, 0.5);
            var B75 = CreateSparse.Random(7, 5, 0.5);

            // Set all diagonal entries to 1.0.
            for (int i = 0; i < 5; i++)
            {
                A55[i, i] = 1.0;
                A57[i, i] = 1.0;
                A75[i, i] = 1.0;
                B55[i, i] = 1.0;
                B57[i, i] = 1.0;
                B75[i, i] = 1.0;
            }

            // Ensure there are no zero rows/columns in A.
            A57[4, 5] = 0.1;
            A57[4, 6] = 0.2;
            A75[5, 4] = 0.1;
            A75[6, 4] = 0.2;

            TestMatricesA = new Dictionary <int, SparseMatrix>();
            TestMatricesB = new Dictionary <int, SparseMatrix>();

            TestMatricesA.Add(55, A55);
            TestMatricesA.Add(57, A57);
            TestMatricesA.Add(75, A75);
            TestMatricesB.Add(55, B55);
            TestMatricesB.Add(57, B57);
            TestMatricesB.Add(75, B75);
        }