File: test2.m

package info (click to toggle)
suitesparse-metis 3.1.0-2
  • links: PTS, VCS
  • area: contrib
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 36,560 kB
  • ctags: 7,484
  • sloc: ansic: 104,515; makefile: 5,984; fortran: 4,591; sh: 1,397; csh: 739; ruby: 603; perl: 219; sed: 164; awk: 18
file content (102 lines) | stat: -rw-r--r-- 1,719 bytes parent folder | download | duplicates (3)
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
function test2
%TEST2 test cs_sparse
%
% Example:
%   test2
% See also: testall

%   Copyright 2006-2007, Timothy A. Davis.
%   http://www.cise.ufl.edu/research/sparse

rand ('state', 0)
% clf

for trial = 1:100
    m = fix (10 * rand (1)) ;
    n = fix (10 * rand (1)) ;
    nz = fix (100 * rand (1)) ;

    i = 1 + fix (m * rand (nz,1)) ;
    j = 1 + fix (n * rand (nz,1)) ;
    x = rand (nz,1) ;

    A = sparse (i,j,x) ;
    B = cs_sparse (i,j,x) ;
    D = cs_sparse2 (i,j,x) ;
    fprintf ('%3d %3d %6d : %6d %6d : %d\n', ...
	m, n, nz, nnz (A), nnz(B), nz-nnz(A)) ;

    err = norm (A-B,1) / norm (A,1) ;
    if (err > 0)
	disp ('err = ') ;
	disp (err) ;
    end
    if (err > 1e-14)
	error ('!') ;
    end

    if (nnz (B-D) > 0)
	error ('!') ;
    end

    if (nnz (A) ~= nnz (B))
	error ('nz!') ;
    end

    if (max (1,nnz (B)) ~= max (1,nzmax (B)))
	nnz (B)
	nzmax (B)
	error ('nzmax!') ;
    end
    % pack


    [m n] = size (A) ;
    p = randperm (m) ;
    q = randperm (n) ;
    C1 = A (p,q) ;
    C2 = cs_permute (A,p,q) ;
    err = norm (C1-C2,1) ;
    if (err > 0)
	error ('!') ;
    end

%    subplot (1,2,1) ; spy (A)
%    subplot (1,2,2) ; spy (C2)
%    drawnow

    x = rand (m,1) ;
    x1 = x (p) ;
    x2 = cs_pvec (x, p) ;

    err = norm (x1-x2,1) ;
    if (err > 0)
	error ('!') ;
    end

    x1 = zeros (m,1) ;
    x1 (p) = x ;							    %#ok
    x2 = cs_ipvec (x, p) ;						    %#ok

    n = min (m,n) ;
    B = A (1:n, 1:n) ;
    p = randperm (n) ;
    B = B+B' ;

    C1 = triu (B (p,p)) ;
    C2 = cs_symperm (B,p) ;

    try
	pp = amd (C2) ;							    %#ok
    catch
	pp = symamd (C2) ;						    %#ok
    end

    err = norm (C1-C2,1) ;
    if (err > 0)
	error ('!') ;
    end



end