6/13/2023 0 Comments Permute matrix matlabWe are back to the question: When a given square sparse matrix can be permuted into a lower triangular form? If the matrix is not coming from LU decomposition, then we may well be in trouble. But in general it is not ok at Mathworks, folks are aware of this ( see here). It is perhaps ok in the context of LU decomposition, in which case one is warned of about the numerical rank deficiency during LU decomposition (before one attempts to solve the linear systems). But this is ok, only if we can recover a full diagonal! What if, at some point, we have rows or columns with no entries at all? The “algorithm” does not handle this case. Then the book hints an algorithm, which builds the permutation matrices essentially by picking a row with a single nonzero, ordering that row and the associated column, and then by deleting both from the matrix and so on. Write an algorithm that determines if the matrix is in this form and, if so, solves …. …Consider a matrix that may be a permuted upper or lower triangular matrix with both rows and columns permuted by unknown permutations and. So this must be taken care of…ĭavis’s “ Direct Methods for Sparse Linear Systems” book (a real gem) asks in its Exercise 3.7: Because, the help page of mldivide says that it tests if a matrix “is square, is not diagonal, looks triangular, is actually triangular, there are zeros in the diagonal, is a permuted triangular”. For “why?” and “who said that?”, see here). These are usually done without worrying if the pivoting took place and permuted those factor matrices (Matlab used to call them psychologically triangular matrices. After all, they have been doing LU decomposition in Matlab and using Matlab’s mldivide (or “backslash”) to solve systems with the factor matrices. This may not be the approach actually used by Matlab, though.For some, the question in the title of this post could look trivial. Putting these three facts together shows that it is possible to do it without a significant amount of extra memory. Transposition can be done inline, requiring only a fixed amount of extra memory, independent of array size, or growing very slowly with array size. Permute(., ) %// interchange dims 3 and 4: we have dims Įach of these elementary operations (interchanging two dimensions) is essentially a transpose along a given plane of the multidimensional array, performed repeatedly along all other dimensions. Permute(., ) %// interchange dims 2 and 4: we have dims For example, permute(x, ) is equivalent to this sequence of elementary permute operations (the sequence is not unique): permute(., ) %// interchange dims 1 and 4: we have dims Permuting of dimensions can always be done as a sequence of elementary permute operations, where" elementary" means interchanging only two dimensions. This is only a guess, as I don't really know what permute does under the hood. While this is not exactly the best way to profile memory usage (better use a proper memory profiler, something like Intel Inspector XE), it does show to some degree that permute is indeed not working in-place. You can see how at its peak the function reached twice as much memory usage as when it returned. I also repeated the test under perfmon.exe which showed the same pattern: I then ran the function simply as: %clear aĪnd watched the memory usage It went from 1.8 gigs in use, and rose to 5.2 then quickly down to 3.6 gigs. I only have 8 gigs of RAM on my laptop, so to avoid thrashing I modified your function as: function out = mtest() I also set the "update speed" to "high" to get a finer time resolution. In Windows 10, I opened the "task manager" on the "performance" tab with the "memory" graphs in view. The permute method in fact does create a second copy of the matrix with the data permuted and returns it. Your argument is flawed because the MATLAB memory profiler is not telling you the truth!
0 Comments
Leave a Reply. |