1function ltest
2%LTEST test lxbpattern
3% Example:
4%   ltest
5% See also cholmod_test, lxtest, ltest2
6
7% Copyright 2013, Timothy A. Davis, http://www.suitesparse.com
8
9rng ('default')
10index = ssget ;
11
12%{
13f = find (index.nrows == index.ncols & index.amd_lnz > 0) ;
14f = setdiff (f, 1425) ; % not really posdef
15[ignore i] = sort (index.amd_lnz (f)) ;
16f = f (i) ;
17%}
18
19f = [ 449 1440 185 56 238 1438 186 57 13 58 97 2203 14 59 72 1177 2204 60 ...
20      436 103 133 232 274 132 109 ] ;
21
22nmat = length (f) ;
23
24for k = 1:nmat
25    id = f (k) ;
26    Prob = ssget (id, index)
27    A = spones (Prob.A) ;
28    n = size (A,1) ;
29    A = A+A' ;
30    p = amd (A) ;
31    A = A (p,p) ;
32    [count, h, parent, post, L] = symbfact (A, 'sym', 'lower') ;
33    L = sparse (1:n, 1:n, count+1, n, n) - sprand (L) / n ;
34
35    % test lxbpattern
36    for i = 1:n
37        b = sparse (i, 1, rand(1), n, 1) ;
38
39        x1 = find (L\b) ;
40        x2 = lxbpattern (L, b) ;
41        s2 = sort (x2)' ;
42        if (~isequal (x1, s2))
43            error ('!') ;
44        end
45
46    end
47
48    for trial = 1:100
49        b = sprand (n, 1, trial/100) ;
50
51        x1 = find (L\b) ;
52        x2 = lxbpattern (L, b) ;
53        s2 = sort (x2)' ;
54        if (~isequal (x1, s2))
55            error ('!') ;
56        end
57
58    end
59
60    b = sparse (rand (n,1)) ;
61
62    x1 = find (L\b) ;
63    x2 = lxbpattern (L, b) ;
64    s2 = sort (x2)' ;
65    if (~isequal (x1, s2))
66        error ('!') ;
67    end
68end
69
70fprintf ('ltest: all tests passed\n') ;
71