Debian Codegraph @

gcc/testsuite/gfortran.dg/ieee/minloc_nan_2.f90

raw
1 ! { dg-do run }
2 !
3 ! PR fortran/90608
4 ! Check the correct behaviour of the inline minloc implementation,
5 ! when the dim argument is present.
6
7 program p
8 implicit none
9 call check_without_mask
10 call check_with_mask
11 contains
12 subroutine check_without_mask()
13 use, intrinsic :: ieee_arithmetic
14 real, allocatable :: a(:,:,:)
15 real :: nan
16 integer, allocatable :: r(:,:)
17 if (.not. ieee_support_nan(nan)) return
18 nan = ieee_value(nan, ieee_quiet_nan)
19 allocate(a(3,4,5), source = nan)
20 r = minloc(a, dim=1)
21 if (any(shape(r) /= (/ 4, 5 /))) error stop 21
22 if (any(r /= 1)) error stop 22
23 r = minloc(a, dim=2)
24 if (any(shape(r) /= (/ 3, 5 /))) error stop 23
25 if (any(r /= 1)) error stop 24
26 r = minloc(a, dim=3)
27 if (any(shape(r) /= (/ 3, 4 /))) error stop 25
28 if (any(r /= 1)) error stop 26
29 end subroutine
30 subroutine check_with_mask()
31 use, intrinsic :: ieee_arithmetic
32 real, allocatable :: a(:,:,:)
33 logical, allocatable :: m(:,:,:)
34 real :: nan
35 integer, allocatable :: r(:,:)
36 if (.not. ieee_support_nan(nan)) return
37 nan = ieee_value(nan, ieee_quiet_nan)
38 allocate(a(2,3,4), source = nan)
39 allocate(m(2,3,4))
40 m(:,:,:) = reshape((/ .false., .false., .true. , .true. , &
41 .false., .true. , .false., .false., &
42 .false., .true. , .true. , .false., &
43 .true. , .true. , .true. , .false., &
44 .false., .true. , .true. , .false., &
45 .false., .true. , .false., .false. /), shape(m))
46 r = minloc(a, dim = 1, mask = m)
47 if (any(shape(r) /= (/ 3, 4 /))) error stop 51
48 if (any(r /= reshape((/ 0, 1, 2, &
49 0, 2, 1, &
50 1, 1, 2, &
51 1, 2, 0 /), (/ 3, 4 /)))) error stop 52
52 r = minloc(a, dim = 2, mask = m)
53 if (any(shape(r) /= (/ 2, 4 /))) error stop 53
54 if (any(r /= reshape((/ 2, 2, &
55 3, 2, &
56 1, 1, &
57 1, 2 /), (/ 2, 4 /)))) error stop 54
58 r = minloc(a, dim = 3, mask = m)
59 if (any(shape(r) /= (/ 2, 3 /))) error stop 55
60 if (any(r /= reshape((/ 3, 3, &
61 1, 1, &
62 2, 1 /), (/ 2, 3 /)))) error stop 56
63 end subroutine
64 end program p