Debian Codegraph @

gcc/testsuite/gfortran.dg/maxloc_with_mask_1.f90

raw
1 ! { dg-do run }
2 !
3 ! PR fortran/90608
4 ! Check the correct behaviour of the inline MAXLOC implementation,
5 ! when there is a mask argument.
6
7 program p
8 implicit none
9 integer, parameter :: data10(*) = (/ 7, 4, 7, 6, 6, 4, 6, 3, 9, 8 /)
10 logical, parameter :: mask10(*) = (/ .false., .true., .false., &
11 .false., .true., .true., &
12 .true. , .true., .false., &
13 .false. /)
14 integer, parameter :: data64(*) = (/ 2, 5, 4, 6, 0, 9, 3, 5, &
15 4, 4, 1, 7, 3, 2, 1, 2, &
16 5, 4, 6, 0, 9, 3, 5, 4, &
17 4, 1, 7, 3, 2, 1, 2, 5, &
18 4, 6, 0, 9, 3, 5, 4, 4, &
19 1, 7, 3, 2, 1, 2, 5, 4, &
20 6, 0, 9, 3, 5, 4, 4, 1, &
21 7, 3, 2, 1, 2, 5, 4, 6 /)
22 logical, parameter :: mask64(*) = (/ .true. , .false., .false., .false., &
23 .true. , .false., .true. , .false., &
24 .false., .true. , .true. , .false., &
25 .true. , .true. , .true. , .true. , &
26 .false., .true. , .false., .true. , &
27 .false., .true. , .false., .true. , &
28 .true. , .false., .false., .true. , &
29 .true. , .true. , .true. , .false., &
30 .false., .false., .true. , .false., &
31 .true. , .false., .true. , .true. , &
32 .true. , .false., .true. , .true. , &
33 .false., .true. , .false., .true. , &
34 .false., .true. , .false., .false., &
35 .false., .true. , .true. , .true. , &
36 .false., .true. , .false., .true. , &
37 .true. , .false., .false., .false. /)
38 call check_int_const_shape_rank_1
39 call check_int_const_shape_rank_3
40 call check_int_const_shape_rank_3_true_mask
41 call check_int_const_shape_rank_3_false_mask
42 call check_int_const_shape_rank_3_optional_mask_present
43 call check_int_const_shape_rank_3_optional_mask_absent
44 call check_int_const_shape_empty_4
45 call check_int_alloc_rank_1
46 call check_int_alloc_rank_3
47 call check_int_alloc_rank_3_true_mask
48 call check_int_alloc_rank_3_false_mask
49 call check_int_alloc_empty_4
50 call check_real_const_shape_rank_1
51 call check_real_const_shape_rank_3
52 call check_real_const_shape_rank_3_true_mask
53 call check_real_const_shape_rank_3_false_mask
54 call check_real_const_shape_rank_3_optional_mask_present
55 call check_real_const_shape_rank_3_optional_mask_absent
56 call check_real_const_shape_empty_4
57 call check_real_alloc_rank_1
58 call check_real_alloc_rank_3
59 call check_real_alloc_rank_3_true_mask
60 call check_real_alloc_rank_3_false_mask
61 call check_real_alloc_empty_4
62 call check_lower_bounds
63 call check_dependencies
64 contains
65 subroutine check_int_const_shape_rank_1()
66 integer :: a(10)
67 logical :: m(10)
68 integer, allocatable :: r(:)
69 a = data10
70 m = mask10
71 r = maxloc(a, mask = m)
72 if (size(r, dim = 1) /= 1) stop 11
73 if (any(r /= (/ 5 /))) stop 12
74 end subroutine
75 subroutine check_int_const_shape_rank_3()
76 integer :: a(4,4,4)
77 logical :: m(4,4,4)
78 integer, allocatable :: r(:)
79 a = reshape(data64, shape(a))
80 m = reshape(mask64, shape(m))
81 r = maxloc(a, mask = m)
82 if (size(r, dim = 1) /= 3) stop 21
83 if (any(r /= (/ 2, 3, 1 /))) stop 22
84 end subroutine
85 subroutine check_int_const_shape_rank_3_true_mask()
86 integer :: a(4,4,4)
87 integer, allocatable :: r(:)
88 a = reshape(data64, shape(a))
89 r = maxloc(a, mask = .true.)
90 if (size(r, dim = 1) /= 3) stop 31
91 if (any(r /= (/ 2, 2, 1 /))) stop 32
92 end subroutine
93 subroutine check_int_const_shape_rank_3_false_mask()
94 integer :: a(4,4,4)
95 integer, allocatable :: r(:)
96 a = reshape(data64, shape(a))
97 r = maxloc(a, mask = .false.)
98 if (size(r, dim = 1) /= 3) stop 41
99 if (any(r /= (/ 0, 0, 0 /))) stop 42
100 end subroutine
101 subroutine call_maxloc_int(r, a, m)
102 integer :: a(:,:,:)
103 logical, optional :: m(:,:,:)
104 integer, allocatable :: r(:)
105 r = maxloc(a, mask = m)
106 end subroutine
107 subroutine check_int_const_shape_rank_3_optional_mask_present()
108 integer :: a(4,4,4)
109 logical :: m(4,4,4)
110 integer, allocatable :: r(:)
111 a = reshape(data64, shape(a))
112 m = reshape(mask64, shape(m))
113 call call_maxloc_int(r, a, m)
114 if (size(r, dim = 1) /= 3) stop 51
115 if (any(r /= (/ 2, 3, 1 /))) stop 52
116 end subroutine
117 subroutine check_int_const_shape_rank_3_optional_mask_absent()
118 integer :: a(4,4,4)
119 integer, allocatable :: r(:)
120 a = reshape(data64, shape(a))
121 call call_maxloc_int(r, a)
122 if (size(r, dim = 1) /= 3) stop 61
123 if (any(r /= (/ 2, 2, 1 /))) stop 62
124 end subroutine
125 subroutine check_int_const_shape_empty_4()
126 integer :: a(9,3,0,7)
127 logical :: m(9,3,0,7)
128 integer, allocatable :: r(:)
129 a = reshape((/ integer:: /), shape(a))
130 m = reshape((/ logical:: /), shape(m))
131 r = maxloc(a, mask = m)
132 if (size(r, dim = 1) /= 4) stop 71
133 if (any(r /= (/ 0, 0, 0, 0 /))) stop 72
134 end subroutine
135 subroutine check_int_alloc_rank_1()
136 integer, allocatable :: a(:)
137 logical, allocatable :: m(:)
138 integer, allocatable :: r(:)
139 allocate(a(10), m(10))
140 a(:) = data10
141 m(:) = mask10
142 r = maxloc(a, mask = m)
143 if (size(r, dim = 1) /= 1) stop 81
144 if (any(r /= (/ 5 /))) stop 82
145 end subroutine
146 subroutine check_int_alloc_rank_3()
147 integer, allocatable :: a(:,:,:)
148 logical, allocatable :: m(:,:,:)
149 integer, allocatable :: r(:)
150 allocate(a(4,4,4), m(4,4,4))
151 a(:,:,:) = reshape(data64, shape(a))
152 m(:,:,:) = reshape(mask64, shape(m))
153 r = maxloc(a, mask = m)
154 if (size(r, dim = 1) /= 3) stop 91
155 if (any(r /= (/ 2, 3, 1 /))) stop 92
156 end subroutine
157 subroutine check_int_alloc_rank_3_true_mask()
158 integer, allocatable :: a(:,:,:)
159 integer, allocatable :: r(:)
160 allocate(a(4,4,4))
161 a(:,:,:) = reshape(data64, shape(a))
162 r = maxloc(a, mask = .true.)
163 if (size(r, dim = 1) /= 3) stop 101
164 if (any(r /= (/ 2, 2, 1 /))) stop 102
165 end subroutine
166 subroutine check_int_alloc_rank_3_false_mask()
167 integer, allocatable :: a(:,:,:)
168 integer, allocatable :: r(:)
169 allocate(a(4,4,4))
170 a(:,:,:) = reshape(data64, shape(a))
171 r = maxloc(a, mask = .false.)
172 if (size(r, dim = 1) /= 3) stop 111
173 if (any(r /= (/ 0, 0, 0 /))) stop 112
174 end subroutine
175 subroutine check_int_alloc_empty_4()
176 integer, allocatable :: a(:,:,:,:)
177 logical, allocatable :: m(:,:,:,:)
178 integer, allocatable :: r(:)
179 allocate(a(9,3,0,7), m(9,3,0,7))
180 a(:,:,:,:) = reshape((/ integer:: /), shape(a))
181 m(:,:,:,:) = reshape((/ logical:: /), shape(m))
182 r = maxloc(a, mask = m)
183 if (size(r, dim = 1) /= 4) stop 121
184 if (any(r /= (/ 0, 0, 0, 0 /))) stop 122
185 end subroutine
186 subroutine check_real_const_shape_rank_1()
187 real :: a(10)
188 logical :: m(10)
189 integer, allocatable :: r(:)
190 a = (/ real:: data10 /)
191 m = mask10
192 r = maxloc(a, mask = m)
193 if (size(r, dim = 1) /= 1) stop 131
194 if (any(r /= (/ 5 /))) stop 132
195 end subroutine
196 subroutine check_real_const_shape_rank_3()
197 real :: a(4,4,4)
198 logical :: m(4,4,4)
199 integer, allocatable :: r(:)
200 a = reshape((/ real:: data64 /), shape(a))
201 m = reshape(mask64, shape(m))
202 r = maxloc(a, mask = m)
203 if (size(r, dim = 1) /= 3) stop 141
204 if (any(r /= (/ 2, 3, 1 /))) stop 142
205 end subroutine
206 subroutine check_real_const_shape_rank_3_true_mask()
207 real :: a(4,4,4)
208 integer, allocatable :: r(:)
209 a = reshape((/ real:: data64 /), shape(a))
210 r = maxloc(a, mask = .true.)
211 if (size(r, dim = 1) /= 3) stop 151
212 if (any(r /= (/ 2, 2, 1 /))) stop 152
213 end subroutine
214 subroutine check_real_const_shape_rank_3_false_mask()
215 real :: a(4,4,4)
216 integer, allocatable :: r(:)
217 a = reshape((/ real:: data64 /), shape(a))
218 r = maxloc(a, mask = .false.)
219 if (size(r, dim = 1) /= 3) stop 161
220 if (any(r /= (/ 0, 0, 0 /))) stop 162
221 end subroutine
222 subroutine call_maxloc_real(r, a, m)
223 real :: a(:,:,:)
224 logical, optional :: m(:,:,:)
225 integer, allocatable :: r(:)
226 r = maxloc(a, mask = m)
227 end subroutine
228 subroutine check_real_const_shape_rank_3_optional_mask_present()
229 real :: a(4,4,4)
230 logical :: m(4,4,4)
231 integer, allocatable :: r(:)
232 a = reshape((/ real:: data64 /), shape(a))
233 m = reshape(mask64, shape(m))
234 call call_maxloc_real(r, a, m)
235 if (size(r, dim = 1) /= 3) stop 171
236 if (any(r /= (/ 2, 3, 1 /))) stop 172
237 end subroutine
238 subroutine check_real_const_shape_rank_3_optional_mask_absent()
239 real :: a(4,4,4)
240 integer, allocatable :: r(:)
241 a = reshape((/ real:: data64 /), shape(a))
242 call call_maxloc_real(r, a)
243 if (size(r, dim = 1) /= 3) stop 181
244 if (any(r /= (/ 2, 2, 1 /))) stop 182
245 end subroutine
246 subroutine check_real_const_shape_empty_4()
247 real :: a(9,3,0,7)
248 logical :: m(9,3,0,7)
249 integer, allocatable :: r(:)
250 a = reshape((/ real:: /), shape(a))
251 m = reshape((/ logical:: /), shape(m))
252 r = maxloc(a, mask = m)
253 if (size(r, dim = 1) /= 4) stop 191
254 if (any(r /= (/ 0, 0, 0, 0 /))) stop 192
255 end subroutine
256 subroutine check_real_alloc_rank_1()
257 real, allocatable :: a(:)
258 logical, allocatable :: m(:)
259 integer, allocatable :: r(:)
260 allocate(a(10), m(10))
261 a(:) = (/ real:: data10 /)
262 m(:) = mask10
263 r = maxloc(a, mask = m)
264 if (size(r, dim = 1) /= 1) stop 201
265 if (any(r /= (/ 5 /))) stop 202
266 end subroutine
267 subroutine check_real_alloc_rank_3()
268 real, allocatable :: a(:,:,:)
269 logical, allocatable :: m(:,:,:)
270 integer, allocatable :: r(:)
271 allocate(a(4,4,4), m(4,4,4))
272 a(:,:,:) = reshape((/ real:: data64 /), shape(a))
273 m(:,:,:) = reshape(mask64, shape(m))
274 r = maxloc(a, mask = m)
275 if (size(r, dim = 1) /= 3) stop 211
276 if (any(r /= (/ 2, 3, 1 /))) stop 212
277 end subroutine
278 subroutine check_real_alloc_rank_3_true_mask()
279 real, allocatable :: a(:,:,:)
280 integer, allocatable :: r(:)
281 allocate(a(4,4,4))
282 a(:,:,:) = reshape((/ real:: data64 /), shape(a))
283 r = maxloc(a, mask = .true.)
284 if (size(r, dim = 1) /= 3) stop 221
285 if (any(r /= (/ 2, 2, 1 /))) stop 222
286 end subroutine
287 subroutine check_real_alloc_rank_3_false_mask()
288 real, allocatable :: a(:,:,:)
289 integer, allocatable :: r(:)
290 allocate(a(4,4,4))
291 a(:,:,:) = reshape((/ real:: data64 /), shape(a))
292 r = maxloc(a, mask = .false.)
293 if (size(r, dim = 1) /= 3) stop 231
294 if (any(r /= (/ 0, 0, 0 /))) stop 232
295 end subroutine
296 subroutine check_real_alloc_empty_4()
297 real, allocatable :: a(:,:,:,:)
298 logical, allocatable :: m(:,:,:,:)
299 integer, allocatable :: r(:)
300 allocate(a(9,3,0,7), m(9,3,0,7))
301 a(:,:,:,:) = reshape((/ real:: /), shape(a))
302 m(:,:,:,:) = reshape((/ logical :: /), shape(m))
303 r = maxloc(a, mask = m)
304 if (size(r, dim = 1) /= 4) stop 241
305 if (any(r /= (/ 0, 0, 0, 0 /))) stop 242
306 end subroutine
307 subroutine check_lower_bounds()
308 real, allocatable :: a(:,:,:)
309 logical, allocatable :: m(:,:,:)
310 integer, allocatable :: r(:)
311 allocate(a(3:6,-1:2,4), m(3:6,-1:2,4))
312 a(:,:,:) = reshape((/ real:: data64 /), shape(a))
313 m = reshape(mask64, shape(m))
314 r = maxloc(a, mask = m)
315 if (size(r, dim = 1) /= 3) stop 251
316 if (any(r /= (/ 2, 3, 1 /))) stop 252
317 end subroutine
318 elemental subroutine set(o, i)
319 integer, intent(out) :: o
320 integer, intent(in) :: i
321 o = i
322 end subroutine
323 subroutine check_dependencies()
324 integer, allocatable :: a(:,:,:)
325 allocate(a(3,3,3))
326 ! Direct assignment
327 a(:,:,:) = reshape(data64(1:27), shape(a))
328 a(1,1,:) = maxloc(a, mask=a>1)
329 print *, a(1,1,:)
330 if (any(a(1,1,:) /= (/ 3, 2, 1 /))) stop 171
331 a(:,:,:) = reshape(data64(2:28), shape(a))
332 a(3,3,:) = maxloc(a, mask=a>1)
333 if (any(a(3,3,:) /= (/ 2, 2, 1 /))) stop 172
334 a(:,:,:) = reshape(data64(3:29), shape(a))
335 a(1,:,1) = maxloc(a, mask=a>1)
336 if (any(a(1,:,1) /= (/ 1, 2, 1 /))) stop 173
337 a(:,:,:) = reshape(data64(5:31), shape(a))
338 a(2,:,2) = maxloc(a, mask=a>1)
339 if (any(a(2,:,2) /= (/ 2, 1, 1 /))) stop 174
340 a(:,:,:) = reshape(data64(6:32), shape(a))
341 a(3,:,3) = maxloc(a, mask=a>1)
342 if (any(a(3,:,3) /= (/ 1, 1, 1 /))) stop 175
343 a(:,:,:) = reshape(data64(7:33), shape(a))
344 a(:,1,1) = maxloc(a, mask=a>1)
345 if (any(a(:,1,1) /= (/ 3, 2, 2 /))) stop 176
346 a(:,:,:) = reshape(data64(8:34), shape(a))
347 a(:,3,3) = maxloc(a, mask=a>1)
348 if (any(a(:,3,3) /= (/ 2, 2, 2 /))) stop 177
349 ! Subroutine assignment
350 a(:,:,:) = reshape(data64(9:35), shape(a))
351 call set(a(1,1,:), maxloc(a, mask=a>1))
352 if (any(a(1,1,:) /= (/ 1, 2, 2 /))) stop 181
353 a(:,:,:) = reshape(data64(10:36), shape(a))
354 call set(a(3,3,:), maxloc(a, mask=a>1))
355 if (any(a(3,3,:) /= (/ 3, 1, 2 /))) stop 182
356 a(:,:,:) = reshape(data64(11:37), shape(a))
357 call set(a(1,:,1), maxloc(a, mask=a>1))
358 if (any(a(1,:,1) /= (/ 2, 1, 2 /))) stop 183
359 a(:,:,:) = reshape(data64(12:38), shape(a))
360 call set(a(2,:,2), maxloc(a, mask=a>1))
361 if (any(a(2,:,2) /= (/ 1, 1, 2 /))) stop 184
362 a(:,:,:) = reshape(data64(13:39), shape(a))
363 call set(a(3,:,3), maxloc(a, mask=a>1))
364 if (any(a(3,:,3) /= (/ 3, 3, 1 /))) stop 185
365 a(:,:,:) = reshape(data64(14:40), shape(a))
366 call set(a(:,1,1), maxloc(a, mask=a>1))
367 if (any(a(:,1,1) /= (/ 2, 3, 1 /))) stop 186
368 a(:,:,:) = reshape(data64(15:41), shape(a))
369 call set(a(:,3,3), maxloc(a, mask=a>1))
370 if (any(a(:,3,3) /= (/ 1, 3, 1 /))) stop 187
371 call set(a(1,:,:), maxloc(a, dim=1))
372 end subroutine check_dependencies
373 end program p