Esempio n. 1
0
        private static void TestReordering()
        {
            Skip.IfNot(TestSettings.TestSuiteSparse, TestSettings.MessageWhenSkippingSuiteSparse);

            int order = SparseSymm5by5.Order;

            int[]  rowIndices  = SparseSymm5by5.CscRowIndices;
            int[]  colOffsets  = SparseSymm5by5.CscColOffsets;
            int[]  permutation = new int[order];
            IntPtr common      = SuiteSparsePInvokes.CreateCommon(0, 0);
            int    status      = SuiteSparsePInvokes.ReorderAMDUpper(order, rowIndices.Length, rowIndices, colOffsets, permutation,
                                                                     out int factorNNZ, common);

            Assert.True(status == 1, "SuiteSparse reordering failed. A possible reason is the lack of enough available memory");
            comparer.AssertEqual(SparseSymm5by5.MatlabPermutationAMD, permutation);

            SuiteSparsePInvokes.DestroyCommon(ref common);
        }
Esempio n. 2
0
        /// <summary>
        /// Find a fill reducing permutation for the sparsity pattern of a symmetric matrix defined by the parameters.
        /// The returned permutation is new-to-old, namely reordered[i] = original[permutation[i]].
        /// </summary>
        /// <param name="order">The number of rows/columns of the symmetric matrix.</param>
        /// <param name="nonZerosUpper">The number of (structural) non-zero entries in the upper triangle of the symmetric
        ///     matrix.</param>
        /// <param name="cscRowIndices">Row indices of the upper triangle entries of the symmetric matrix, in Compressed Sparse
        ///     Columns format. All row indices of the same column must be sorted.</param>
        /// <param name="cscColOffsets">Column offsets of the upper triangle entries of the symmetric matrix, in Compressed
        ///     Sparse Columns format. All column offsets must be sorted.</param>
        /// <returns>permutation: An array containing the new-to-old fill reducing permutation.
        ///     stats: Measuments taken by SuiteSparse during the execution of AMD.</returns>
        /// <exception cref="SuiteSparseException">Thrown if SuiteSparse dlls cannot be loaded or if AMD fails.</exception>
        public (int[] permutation, ReorderingStatistics stats) FindPermutation(int order, int nonZerosUpper, int[] cscRowIndices,
                                                                               int[] cscColOffsets)
        {
            var    permutation = new int[order];
            IntPtr common      = SuiteSparsePInvokes.CreateCommon(0, 0);

            if (common == IntPtr.Zero)
            {
                throw new SuiteSparseException("Failed to initialize SuiteSparse.");
            }
            int status = SuiteSparsePInvokes.ReorderAMDUpper(order, nonZerosUpper, cscRowIndices, cscColOffsets, permutation,
                                                             out int nnzFactor, common);

            if (status == 0)
            {
                throw new SuiteSparseException("AMD failed. This could be caused by the matrix being so large it"
                                               + " cannot be processed with the available memory.");
            }
            SuiteSparsePInvokes.DestroyCommon(ref common);
            return(permutation, new ReorderingStatistics(nnzFactor, -1));
        }