File: test3.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 (112 lines) | stat: -rw-r--r-- 2,213 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
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
function test3
%TEST3 test cs_lsolve, cs_ltsolve, cs_usolve, cs_chol
%
% Example:
%   test3
% See also: testall

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

clear
index = ssget ;
[ignore f] = sort (max (index.nrows, index.ncols)) ;
f = f (1:100) ;

clf
% f = f(1)

for i = f

    Prob = ssget (i) ;
    disp (Prob) ;

    for cmplex = 0:double(~ispc)

        A = Prob.A ;
        [m n] = size (A) ;
        if (m ~= n)
            continue
        end

        if (cmplex)
            A = A + 1i*sprand(A) ;
        end

        A = A*A' + 2*n*speye (n) ;
        try
            p = amd (A) ;
        catch
            p = symamd (A) ;
        end
        try
            L0 = chol (A)' ;
        catch
            continue
        end
        b = rand (n,1) ;

        if (~ispc)
            if (mod (i,2) == 1)
                b = b + 1i*rand(n,1) ;
            end
        end

        C = A(p,p) ;
        c = condest (C) ;
        fprintf ('condest: %g\n', c) ;

        x1 = L0\b ;
        x2 = cs_lsolve (L0,b) ;
        err = norm (x1-x2,1) ;
        if (err > 1e-12 * c)
            error ('!') ;
        end

        x1 = L0'\b ;
        x2 = cs_ltsolve (L0,b) ;
        err = norm (x1-x2,1) ;
        if (err > 1e-10 * c)
            error ('!') ;
        end

        U = L0' ;

        x1 = U\b ;
        x2 = cs_usolve (U,b) ;
        err = norm (x1-x2,1) ;
        if (err > 1e-10 * c)
            error ('!') ;
        end

        L2 = cs_chol (A) ;
        subplot (2,3,1) ; spy (L0) ;
        subplot (2,3,4) ; spy (L2) ;
        err = norm (L0-L2,1) ;
        if (err > 1e-8 * c)
            error ('!') ;
        end

        L1 = chol (C)' ;
        L2 = cs_chol (C) ;
        subplot (2,3,2) ; spy (L1) ;
        subplot (2,3,5) ; spy (L2) ;
        err = norm (L1-L2,1) ;
        if (err > 1e-8 * c)
            error ('!') ;
        end

        [L3,p] = cs_chol (A) ;
        C = A(p,p) ;
        L4 = chol (C)' ;
        subplot (2,3,3) ; spy (L4) ;
        subplot (2,3,6) ; spy (L3) ;
        err = norm (L4-L3,1) ;
        if (err > 1e-8 * c)
            error ('!') ;
        end

        drawnow

    end
end