1function test12 (cover)
2%TEST12 test Wathen matrix generation
3%
4% Usage: test12(cover)
5%
6% if cover=1, do quick statement coverage tests
7% if cover=0, run larger problems
8
9% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
10% SPDX-License-Identifier: Apache-2.0
11
12if (nargin < 1)
13    cover = 1 ;
14end
15
16if (cover)
17    nn = [20] ;
18else
19    nn = [200 400 800] ;
20end
21
22rng ('default') ;
23
24A = GB_mex_wathen (2,2) ;
25assert (GB_spok (A) == 1) ;
26assert (nnz (A-A') == 0) ;
27
28% this test is too slow when debugging
29debug = GB_mex_debug ;
30
31fprintf ('\nWathen matrices:\n') ;
32
33    for nx = [1 5 10] % 1:20
34        fprintf ('%d:', nx) ;
35        for ny = [1 5 10] % 1:20
36            fprintf ('%d', ny) ;
37
38            for scale = 0:1
39                % reset the random number generator so RHO can be found
40                rng ('default') ;
41                rho = 100 * rand (nx,ny) ;
42                rng ('default') ;
43                A = gallery ('wathen' ,nx, ny, scale) ;
44                anorm = norm (A,1) ;
45                for method = 0:3
46                    fprintf ('.') ;
47                    B = GB_mex_wathen (nx, ny, method, scale, rho) ;
48                    assert (norm (A-B,1) < 16 * eps (norm (A,1))) ;
49                end
50            end
51        end
52    end
53
54    for nx = nn
55        for ny = nn
56            rho = 100 * rand (nx,ny) ;
57
58            for scale = 0:1
59                fprintf ('\n') ;
60                % reset the random number generator so RHO can be found
61                % and given to GB_mex_wathen.m
62                rng ('default') ;
63                rho = 100 * rand (nx,ny) ;
64                rng ('default') ;
65                tic
66                A = gallery ('wathen' ,nx, ny, scale) ;
67                t1 = toc ;
68                n = size (A,1) ;
69                nz = nnz (A) ;
70                for method = 0:3
71                    tic
72                    B = GB_mex_wathen (nx, ny, method, scale, rho) ;
73                    t2 = toc ;
74                    assert (norm (A-B,1) < 16 * eps (norm (A,1))) ;
75                    fprintf ('nx %d ny %d n %d nz %d MATLAB %10.4f GB %10.4f speedup %g\n', ...
76                    nx, ny, n, nz, t1, t2, t1/t2) ;
77                end
78            end
79        end
80    end
81
82% end
83
84fprintf ('test12: all tests passed\n') ;
85
86