~logan/ubuntu/trusty/suitesparse/4.2.1-3ubuntu1

« back to all changes in this revision

Viewing changes to CXSparse/MATLAB/Test/test_randperms.m

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2007-05-29 09:36:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529093629-zowquo0b7slkk6nc
Tags: 3.0.0-2
* suitesparse builds properly twice in a row
* Bug fix: "suitesparse - FTBFS: Broken build depens: libgfortran1-dev",
  thanks to Bastian Blank (Closes: #426349).
* Bug fix: "suitesparse_3.0.0-1: FTBFS: build-depends on
  libgfortran1-dev", thanks to Steve Langasek (Closes: #426354).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function test_randperms
 
2
%TEST_RANDPERMS test random permutations
 
3
% Example:
 
4
%   test_randperms
 
5
% See also: testall
 
6
 
 
7
%   Copyright 2006-2007, Timothy A. Davis.
 
8
%   http://www.cise.ufl.edu/research/sparse
 
9
 
 
10
rand ('state', 0)
 
11
 
 
12
for trial = 1:100
 
13
    m = fix (30 * rand (1)) ;
 
14
    n = fix (30 * rand (1)) ;
 
15
    d = rand (1) ;
 
16
    A = sprandn (m,n,d) ;
 
17
 
 
18
    if (m == 0)
 
19
        p = [] ;
 
20
    else
 
21
        p = randperm (m) ;
 
22
    end
 
23
    if (n == 0)
 
24
        q = [] ;
 
25
    else
 
26
        q = randperm (n) ;
 
27
    end
 
28
 
 
29
    C = A(p,q) ;
 
30
 
 
31
    Im = speye (m) ;
 
32
    In = speye (n) ;
 
33
    P = Im (p,:) ;
 
34
    Q = In (:,q) ;
 
35
 
 
36
    q2 = find (Q) ;
 
37
    if (any (q ~= q2'))
 
38
        error ('!') 
 
39
    end
 
40
 
 
41
    p2 = find (P') ;
 
42
    if (any (p ~= p2'))
 
43
        error ('!') 
 
44
    end
 
45
 
 
46
    E = P*A*Q ;
 
47
    if (norm (C-E,1) ~= 0)
 
48
        error ('!') 
 
49
    end
 
50
 
 
51
    P = sparse (1:m, p, 1) ;
 
52
    Q = sparse (q, 1:n, 1) ;
 
53
 
 
54
    E = P*A*Q ;
 
55
    if (norm (C-E,1) ~= 0)
 
56
        error ('2!') 
 
57
    end
 
58
 
 
59
end
 
60