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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
function test19
%TEST19 test cs_dmperm, cs_maxtransr, cs_dmspy, cs_scc, cspy
%
% Example:
% test19
% See also: testall
% CXSparse, Copyright (c) 2006-2022, Timothy A. Davis. All Rights Reserved.
% SPDX-License-Identifier: LGPL-2.1+
clear functions
randn ('state', 0) ;
rand ('state', 0) ;
clf
for trials = 1:100
m = fix (100 * rand (1)) ;
n = fix (100 * rand (1)) ;
% d = 0.1 * rand (1) ;
d = rand (1) * 4 * max (m,n) / max (m*n,1) ;
A = sprandn (m,n,d) ;
S = sprandn (m,m,d) + speye (m) ;
if (~ispc)
if (rand ( ) > .5)
A = A + 1i * sprand (A) ;
end
if (rand ( ) > .5)
S = S + 1i * sprand (S) ;
end
end
subplot (2,3,1) ;
cspy (A) ;
pp = dmperm (A) ;
sprnk = sum (pp > 0) ;
pp2 = cs_dmperm (A) ;
spr2 = sum (pp2 > 0) ;
if (spr2 ~= sprnk)
error ('!')
end
pp2 = cs_maxtransr (A) ;
spr2 = sum (pp2 > 0) ;
if (spr2 ~= sprnk)
error ('!')
end
[p,q,r,s] = dmperm (A) ;
C = A (p,q) ;
% r
% s
nk = length (r) - 1 ;
fprintf ('sprnk: %d m %d n %d nb: %d\n', sprnk, m, n, nk) ;
subplot (2,3,2) ;
hold off
spy (C)
hold on
for k = 1:nk
r1 = r(k) ;
r2 = r(k+1) ;
c1 = s(k) ;
c2 = s(k+1) ;
plot ([c1 c2 c2 c1 c1]-.5, [r1 r1 r2 r2 r1]-.5, 'g') ;
end
[p2,q2,rr2,ss2,cp,rp] = cs_dmperm (A) ;
if (min (m,n) > 0)
if (length (rr2) ~= length (r))
error ('# fine blocks!') ;
end
end
if (rp (4) - 1 ~= sprnk)
rp %#ok
sprnk %#ok
error ('!') ;
end
if (any (sort (p2) ~= 1:m))
error ('p2!') ;
end
if (any (sort (q2) ~= 1:n))
error ('q2!') ;
end
if (cp (5) ~= n+1)
error ('cp!') ;
end
if (rp (5) ~= m+1)
error ('rp!') ;
end
C = A (p2,q2) ;
subplot (2,3,3) ; cs_dmspy (A,0) ;
% hold off
% spy (C) ;
% hold on
% r1 = rp(1) ;
% r2 = rp(2) ;
% c1 = cp(1) ;
% c2 = cp(2) ;
% plot ([c1 c2 c2 c1 c1]-.5, [r1 r1 r2 r2 r1]-.5, 'g') ;
r1 = rp(1) ;
r2 = rp(2) ;
c1 = cp(2) ;
c2 = cp(3) ;
% plot ([c1 c2 c2 c1 c1]-.5, [r1 r1 r2 r2 r1]-.5, 'g') ;
B = C (r1:r2-1, c1:c2-1) ;
if (nnz (diag (B)) ~= size (B,1))
error ('C1 diag!') ;
end
r1 = rp(2) ;
r2 = rp(3) ;
c1 = cp(3) ;
c2 = cp(4) ;
% plot ([c1 c2 c2 c1 c1]-.5, [r1 r1 r2 r2 r1]-.5, 'r') ;
B = C (r1:r2-1, c1:c2-1) ;
if (nnz (diag (B)) ~= size (B,1))
error ('C2 diag!') ;
end
r1 = rp(3) ;
r2 = rp(4) ;
c1 = cp(4) ;
c2 = cp(5) ;
% plot ([c1 c2 c2 c1 c1]-.5, [r1 r1 r2 r2 r1]-.5, 'g') ;
B = C (r1:r2-1, c1:c2-1) ;
if (nnz (diag (B)) ~= size (B,1))
error ('C3 diag!') ;
end
r1 = rp(4) ; %#ok
r2 = rp(5) ; %#ok
c1 = cp(4) ; %#ok
c2 = cp(5) ; %#ok
% plot ([c1 c2 c2 c1 c1]-.5, [r1 r1 r2 r2 r1]-.5, 'g') ;
if (~isempty (S))
[p1,q1,r0,s0] = dmperm (S) ;
[p3,r3] = cs_scc (S) ;
if (length (r3) ~= length (r0))
error ('scc size!') ;
end
if (any (sort (p3) ~= 1:m))
error ('scc perm!') ;
end
nk = length (r0)-1 ;
subplot (2,3,4) ;
hold off
spy (S (p1,q1)) ;
hold on
for k = 1:nk
r1 = r0(k) ;
r2 = r0(k+1) ;
c1 = s0(k) ;
c2 = s0(k+1) ;
plot ([c1 c2 c2 c1 c1]-.5, [r1 r1 r2 r2 r1]-.5, 'g') ;
end
subplot (2,3,5) ;
hold off
spy (S (p3,p3)) ;
hold on
for k = 1:nk
r1 = r3(k) ;
r2 = r3(k+1) ;
c1 = r3(k) ;
c2 = r3(k+1) ;
plot ([c1 c2 c2 c1 c1]-.5, [r1 r1 r2 r2 r1]-.5, 'g') ;
end
end
subplot (2,3,6) ;
cs_dmspy (A) ;
drawnow
% pause
end
|