File: test54.m

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (166 lines) | stat: -rw-r--r-- 4,578 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
function test54
%TEST54 test GB_subref: numeric case with I=lo:hi, J=lo:hi

% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0

fprintf ('\ntest54: ==== quick test for subref and assign (lo:stride:hi):\n') ;
clear

m = 5 ;
n = 7 ;
A = sprandn (m,n,0.4) ;

for ilo = 1:m
    for ihi = ilo:m
        for jlo = 1:n
            for jhi = jlo:m

                C = A (ilo:ihi,jlo:jhi) ;

                I1 = uint64 (ilo:ihi) - 1 ;
                J1 = uint64 (jlo:jhi) - 1 ;
                C1 = GB_mex_Matrix_subref (A, I1, J1) ;
                assert (isequal (C, C1)) ;

                I2.begin = ilo-1 ;
                I2.end   = ihi-1 ;
                J2.begin = jlo-1 ;
                J2.end   = jhi-1 ;
                C2 = GB_mex_Matrix_subref (A, I2, J2) ;
                assert (isequal (C, C2)) ;

            end
        end
    end
end

C = sprandn (m, n, 0.4) ;

for ilo = 1:m
    for ihi = ilo:m

        sm = ihi-ilo+1 ;
        S = sprandn (sm, n, 0.4) ;

        C0 = C ;
        C0 (ilo:ihi,:) = S ;

        I1 = uint64 (ilo:ihi) - 1 ;
        C1 = GB_mex_subassign (C, [ ], [ ], S, I1, [ ], [ ]) ;
        assert (isequal (C0, C1.matrix)) ;

        C1b = GB_mex_assign (C, [ ], [ ], S, I1, [ ], [ ]) ;
        assert (isequal (C0, C1b.matrix)) ;

        I2.begin = ilo-1 ;
        I2.end   = ihi-1 ;
        C2 = GB_mex_subassign (C, [ ], [ ], S, I2, [ ], [ ]) ;
        assert (isequal (C0, C2.matrix)) ;

        C2b = GB_mex_assign (C, [ ], [ ], S, I2, [ ], [ ]) ;
        assert (isequal (C0, C2b.matrix)) ;

        S = sprandn (m, sm, 0.4) ;

        C0 = C ;
        C0 (:,ilo:ihi) = S ;

        C1 = GB_mex_subassign (C, [ ], [ ], S, [ ], I1, [ ]) ;
        assert (isequal (C0, C1.matrix)) ;

        C1b = GB_mex_assign (C, [ ], [ ], S, [ ], I1, [ ]) ;
        assert (isequal (C0, C1b.matrix)) ;

        C2 = GB_mex_subassign (C, [ ], [ ], S, [ ], I2, [ ]) ;
        assert (isequal (C0, C2.matrix)) ;

        C2b = GB_mex_assign (C, [ ], [ ], S, [ ], I2, [ ]) ;
        assert (isequal (C0, C2b.matrix)) ;

        for jlo = 1:n
            for jhi = jlo:n

                sm = ihi-ilo+1 ;
                sn = jhi-jlo+1 ;
                S = sprandn (sm, sn, 0.4) ;

                C0 = C ;
                C0 (ilo:ihi,jlo:jhi) = S ;

                I1 = uint64 (ilo:ihi) - 1 ;
                J1 = uint64 (jlo:jhi) - 1 ;
                C1 = GB_mex_subassign (C, [ ], [ ], S, I1, J1, [ ]) ;
                assert (isequal (C0, C1.matrix)) ;

                C1b = GB_mex_assign (C, [ ], [ ], S, I1, J1, [ ]) ;
                assert (isequal (C0, C1b.matrix)) ;

                I2.begin = ilo-1 ;
                I2.end   = ihi-1 ;
                J2.begin = jlo-1 ;
                J2.end   = jhi-1 ;
                C2 = GB_mex_subassign (C, [ ], [ ], S, I2, J2, [ ]) ;
                assert (isequal (C0, C2.matrix)) ;

                C2b = GB_mex_assign (C, [ ], [ ], S, I2, J2, [ ]) ;
                assert (isequal (C0, C2b.matrix)) ;

            end
        end
    end
end

clear C0 C1 C1b C2 C2b I1 J1 I2 J2

fprintf ('longer tests: ') ;
jinc_list = unique ([-1 1 3]) ;

for ibegin = 1:m
    for iend = 1:m
        for iinc = -m:m

            I = ibegin:iinc:iend ;
            I1.begin = ibegin - 1 ;
            I1.inc = iinc ;
            I1.end = iend - 1 ;

            fprintf ('.') ;

            for jbegin = 1:3:n
                for jend = 1:3:n
                    for jinc = jinc_list

                        J = jbegin:jinc:jend ;
                        J1.begin = jbegin - 1 ;
                        J1.inc = jinc ;
                        J1.end = jend - 1 ;

                        sm = length (I) ;
                        sn = length (J) ;
                        S = sprandn (sm, sn, 0.4) ;

                        C0 = C ;
                        C0 (I,J) = S ;

                        % fprintf ('\nsubassign:\n') ;
                        C1 = GB_mex_subassign (C, [ ], [ ], S, I1, J1, [ ]) ;
                        assert (isequal (C0, C1.matrix)) ;

                        % fprintf ('\nassign:\n') ;
                        C2 = GB_mex_assign (C, [ ], [ ], S, I1, J1, [ ]) ;
                        assert (isequal (C0, C2.matrix)) ;

                        R = C(I,J) ;
                        R1 = GB_mex_Matrix_subref (C, I1, J1) ;
                        assert (isequal (R, R1)) ;

                    end
                end
            end
        end
    end
end


fprintf ('\ntest54: all tests passed\n') ;