File: test54.m

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (178 lines) | stat: -rw-r--r-- 5,020 bytes parent folder | download | duplicates (2)
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
167
168
169
170
171
172
173
174
175
176
177
178
function test54
%TEST54 test GB_subref: numeric case with I=lo:hi, J=lo:hi

% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2025, 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)) ;

        % with GrB_Vector:
        C1 = GB_mex_subassign (C, [ ], [ ], S, I1, [ ], [ ], 5) ;
        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)) ;

        % with GrB_Vector:
        C1 = GB_mex_subassign (C, [ ], [ ], S, [ ], I1, [ ], 5) ;
        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)) ;

                % with GrB_Vector
                C1 = GB_mex_subassign (C, [ ], [ ], S, I1, J1, [ ], 5) ;
                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') ;