1function test1 2%TEST1 test cs_transpose, cs_gaxpy, cs_sparse, cs_sparse2 3% 4% Example: 5% test1 6% See also: testall 7 8% Copyright 2006-2012, Timothy A. Davis, http://www.suitesparse.com 9 10index = ssget ; 11[ignore f] = sort (max (index.nrows, index.ncols)) ; 12f = f (1:100) ; 13 14for ii = f 15 16 Prob = ssget (ii) ; 17 disp (Prob) ; 18 for cmplex = 0:double(~ispc) 19 20 A = Prob.A ; 21 if (cmplex) 22 A = A + 1i*sprand(A) ; 23 end 24 25 B = A' ; 26 C = cs_transpose (A) ; 27 if (nnz (B-C) ~= 0) 28 error ('!') 29 end 30 31 C = cs_transpose (A,0) ; 32 if (nnz (A.'-C) ~= 0) 33 error ('!') 34 end 35 36 C = cs_transpose (A,1) ; 37 if (nnz (A'-C) ~= 0) 38 error ('!') 39 end 40 41 [m n] = size (A) ; 42 % if (m == n) 43 x = rand (n,1) ; 44 y = rand (m,1) ; 45 z = y+A*x ; 46 q = cs_gaxpy (A,x,y) ; 47 err = norm (z-q,1) / norm (z,1) ; 48 disp (err) ; 49 if (err > 1e-13) 50 error ('!') 51 end 52 % end 53 54 if (~ispc) 55 x = x + 1i*rand (n,1) ; 56 y = y + 1i*rand (m,1) ; 57 z = y+A*x ; 58 q = cs_gaxpy (A,x,y) ; 59 err = norm (z-q,1) / norm (z,1) ; 60 disp (err) ; 61 if (err > 1e-13) 62 error ('!') 63 end 64 end 65 66 [i j x] = find (A) ; 67 p = randperm (length (i)) ; 68 i = i (p) ; 69 j = j (p) ; 70 x = x (p) ; 71 if (m <= 1) 72 % The find function returns row vectors i,j,x when size(A,1) is 1. 73 % This is fine for the MATLAB 'sparse', but not for cs_sparse. 74 i = i (:) ; 75 j = j (:) ; 76 x = x (:) ; 77 end 78 D = sparse (i,j,x) ; 79 E = cs_sparse (i,j,x) ; 80 % [i j x] 81 F = cs_sparse2 (i,j,x) ; 82 if (nnz (D-E) ~= 0) 83 error ('!') 84 end 85 if (nnz (F-E) ~= 0) 86 error ('!') 87 end 88 89 clear A B C D E F 90 % pause 91 92 end 93end 94