1function test81
2%TEST81 test GrB_Matrix_extract with index range, stride, & backwards
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('test81:  GrB_Matrix_extract with index range, stride, backwards\n') ;
8
9rng ('default') ;
10
11n = 10 ;
12A = sprand (n, n, 0.5) ;
13S = sparse (n, n) ;
14
15Ahyper.matrix = A ;
16Ahyper.is_hyper = true ;
17Ahyper.is_csc = true ;
18
19for ilo = 1:2:n
20    for ihi = 1:2:n
21        fprintf ('#') ;
22        for i_inc = [-n:n inf]
23            clear I
24            I.begin = ilo-1 ;
25            I.end = ihi-1 ;
26            if (isfinite (i_inc))
27                I.inc = i_inc ;
28                iinc = i_inc ;
29            else
30                iinc = 1 ;
31            end
32
33            fprintf (':') ;
34            for jlen = [1:2:n]
35                clear J
36                J = randperm (n) ;
37                J = J (1:jlen) ;
38                J0 = uint64 (J) - 1 ;
39                C1 = A (ilo:iinc:ihi, J) ;
40                [sm sn] = size (C1) ;
41                S = sparse (sm, sn) ;
42                C2 = GB_mex_Matrix_extract (S, [ ], [ ], A, I, J0, [ ]) ;
43                assert (isequal (C1, C2.matrix)) ;
44                C3 = GB_mex_Matrix_extract (S, [ ], [ ], ...
45                    Ahyper, I, J0, [ ]) ;
46                assert (isequal (C1, C3.matrix)) ;
47            end
48
49            fprintf ('.') ;
50            for jlo = 1:2:n
51                for jhi = 1:2:n
52                    for j_inc = [-n:n inf]
53
54                        clear J
55                        J.begin = jlo-1 ;
56                        J.end = jhi-1 ;
57                        if (isfinite (j_inc))
58                            J.inc = j_inc ;
59                            jinc = j_inc ;
60                        else
61                            jinc = 1 ;
62                        end
63
64                        C1 = A (ilo:iinc:ihi, jlo:jinc:jhi) ;
65                        [sm sn] = size (C1) ;
66                        S = sparse (sm, sn) ;
67
68                        C2 = GB_mex_Matrix_extract (S, [ ], [ ], A, I, J, [ ]) ;
69                        assert (isequal (C1, C2.matrix)) ;
70
71                        C3 = GB_mex_Matrix_extract (S, [ ], [ ], ...
72                            Ahyper, I, J, [ ]) ;
73                        assert (isequal (C1, C3.matrix)) ;
74
75                    end
76                end
77            end
78
79        end
80    end
81end
82
83fprintf ('\ntest81: all tests passed\n') ;
84
85