File: test10.m

package info (click to toggle)
ufsparse 1.2-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 27,536 kB
  • ctags: 5,848
  • sloc: ansic: 89,328; makefile: 4,721; fortran: 1,991; csh: 207; sed: 162; awk: 33; java: 30; sh: 8
file content (84 lines) | stat: -rw-r--r-- 1,624 bytes parent folder | download
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

clear

rand ('state', 0) ;


% f = 185 ;
% f = 449 ;
clf

for trials = 1:100
    
    m = fix (100 * rand (1)) ;
    n = fix (100 * rand (1)) ;
    d = 0.1 * rand (1) ;
    A = sprandn (m, n, d) ;
    [m n] = size (A) ;
    if (m < n)
	A = A' ;
    end
    [m n] = size (A) ;
    sp = sprank (A) ;
    % if (sp < n)
    %	continue ;
    % end

    Aorig = A ;

    % A = A (:, colamd (A)) ;

    tic ;
    R = qr (A) ;
    t1 = toc ;

    % tic ;
    % [Q,R] = qr (A) ;
    % t1 = toc ;

    [c,h,parent] = symbfact (A, 'col') ;
    rnz = sum (c) ;
    tic ;
    [V2,Beta2,p,R2] = cs_qr (sparse(A)) ;
    t2 = toc ;

    C = A ;
    m2 = size (V2,1) ;
    if (m2 > m)
	C = [A ; sparse(m2-m, n)] ;
    end
    C = C (p,:) ;

    [H1,R1] = myqr (C) ;
    err1 = norm (R1-R2,1) / norm (R1)
    % [svd(A) svd(R1) svd(full(R2))]
    s1 = svd (full (A)) ;
    s2 = svd (full (R2)) ;
    if (n > 0)
	err2 = norm (s1 - s2) / s1 (1) 
    else
	err2 = 0 ;
    end
    fprintf ('%10.6f %10.6f  cs speedup %8.3f sprank %d vs %d\n', t1, t2, t1/t2, sp, n) ;

    % H2 = full (H2)
    % R2 = full (R2)

    subplot (2,4,1) ; spy (A) ;		title ('A colamd') ;
    subplot (2,4,4) ; spy (Aorig) ;	title ('Aorig') ;
    subplot (2,4,2) ; spy (C) ;		title ('A rperm') ;
    subplot (2,4,5) ; spy (abs(R2)>0) ;	title ('spqr R, no zeros') ;
    subplot (2,4,6) ; spy (R) ;		title ('matlab R') ;
    subplot (2,4,7) ; spy (R2) ;	title ('spqr R') ;
    subplot (2,4,8) ; spy (V2) ;	title ('spqr H') ;
    drawnow

    if (err2 > 1e-9)
	error ('!') ;
    end

    if (m2 > m)
	fprintf ('added %d rows, sprank %d n %d\n', m2-m, sp, n) ;
    end
end