1function [p,q,r,s,cc,rr] = cs_dmspy (A,res,seed) 2%CS_DMSPY plot the Dulmage-Mendelsohn decomposition of a matrix. 3% [p,q,r,s,cc,rr] = cs_dmspy(A) computes [p,q,r,s,cc,rr] = cs_dmperm(A), 4% does spy(A(p,q)), and then draws boxes around the coarse and fine 5% decompositions. A 2nd input argument (cs_dmspy(A,res)) changes the 6% resolution of the image to res-by-res (default resolution is 256). 7% If res is zero, spy is used instead of cspy. If the resolution is low, the 8% picture of the blocks in the figure can overlap. They do not actually 9% overlap in the matrix. With 3 arguments, cs_dmspy(A,res,seed), 10% cs_dmperm(A,seed) is used, where seed controls the randomized algorithm 11% used by cs_dmperm. 12% 13% Example: 14% Prob = ssget ('HB/arc130') ; cs_dmspy (Prob.A) ; 15% 16% See also CS_DMPERM, CS_DMSOL, DMPERM, SPRANK, SPY. 17 18% Copyright 2006-2012, Timothy A. Davis, http://www.suitesparse.com 19 20if (~issparse (A)) 21 A = sparse (A) ; 22end 23if (nargin < 2) 24 res = 256 ; 25end 26if (nargin < 3) 27 seed = 0 ; 28end 29 30% Dulmage-Mendelsohn permutation 31[p1,q,r,s,cc,rr] = cs_dmperm (A,seed) ; 32if (nargout > 0) 33 p = p1 ; 34end 35 36nb = length (r)-1 ; 37 38% plot the result 39S = A (p1,q) ; 40if (res == 0) 41 spy (S) ; 42 e = 1 ; 43else 44 e = cspy (S,res) ; 45end 46hold on 47 48title (sprintf ( ... 49 '%d-by-%d, sprank: %d, fine blocks: %d, coarse blocks: %d-by-%d\n', ... 50 size (A), rr(4)-1, nb, length (find (diff (rr))), ... 51 length (find (diff (cc))))) ; 52 53drawboxes (nb, e, r, s) ; 54 55[m n] = size (A) ; 56drawbox (1,m+1,1,n+1,'k',1,e) ; 57 58drawbox (rr(1), rr(2), cc(1), cc (2), 'r', 2, e) ; 59drawbox (rr(1), rr(2), cc(2), cc (3), 'r', 2, e) ; 60drawbox (rr(2), rr(3), cc(3), cc (4), 'k', 2, e) ; 61drawbox (rr(3), rr(4), cc(4), cc (5), 'r', 2, e) ; 62drawbox (rr(4), rr(5), cc(4), cc (5), 'r', 2, e) ; 63 64hold off 65 66