File: cs_dmspy.m

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (66 lines) | stat: -rw-r--r-- 1,862 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function [p,q,r,s,cc,rr] = cs_dmspy (A,res,seed)
%CS_DMSPY plot the Dulmage-Mendelsohn decomposition of a matrix.
%   [p,q,r,s,cc,rr] = cs_dmspy(A) computes [p,q,r,s,cc,rr] = cs_dmperm(A),
%   does spy(A(p,q)), and then draws boxes around the coarse and fine
%   decompositions.  A 2nd input argument (cs_dmspy(A,res)) changes the
%   resolution of the image to res-by-res (default resolution is 256).
%   If res is zero, spy is used instead of cspy.  If the resolution is low, the
%   picture of the blocks in the figure can overlap.  They do not actually
%   overlap in the matrix.  With 3 arguments, cs_dmspy(A,res,seed),
%   cs_dmperm(A,seed) is used, where seed controls the randomized algorithm
%   used by cs_dmperm.
%
%   Example:
%       Prob = ssget ('HB/arc130') ; cs_dmspy (Prob.A) ;
%
%   See also CS_DMPERM, CS_DMSOL, DMPERM, SPRANK, SPY.

% CXSparse, Copyright (c) 2006-2022, Timothy A. Davis. All Rights Reserved.
% SPDX-License-Identifier: LGPL-2.1+

if (~issparse (A))
    A = sparse (A) ;
end
if (nargin < 2)
    res = 256 ;
end
if (nargin < 3)
    seed = 0 ;
end

% Dulmage-Mendelsohn permutation
[p1,q,r,s,cc,rr] = cs_dmperm (A,seed) ;
if (nargout > 0)
    p = p1 ;
end

nb = length (r)-1 ;

% plot the result
S = A (p1,q) ;
if (res == 0)
    spy (S) ;
    e = 1 ;
else
    e = cspy (S,res) ;
end
hold on

title (sprintf ( ...
    '%d-by-%d, sprank: %d, fine blocks: %d, coarse blocks: %d-by-%d\n', ...
    size (A), rr(4)-1, nb, length (find (diff (rr))), ...
    length (find (diff (cc))))) ;

drawboxes (nb, e, r, s) ;

[m n] = size (A) ;
drawbox (1,m+1,1,n+1,'k',1,e) ;

drawbox (rr(1), rr(2), cc(1), cc (2), 'r', 2, e) ;
drawbox (rr(1), rr(2), cc(2), cc (3), 'r', 2, e) ;
drawbox (rr(2), rr(3), cc(3), cc (4), 'k', 2, e) ;
drawbox (rr(3), rr(4), cc(4), cc (5), 'r', 2, e) ;
drawbox (rr(4), rr(5), cc(4), cc (5), 'r', 2, e) ;

hold off