Debian Codegraph @

gcc/testsuite/gfortran.dg/class_transformational_2.f90

raw
1 ! { dg-do run }
2 !
3 ! Test transformational intrinsics other than reshape with class results.
4 ! This emerged from PR102689, for which class_transformational_1.f90 tests
5 ! class-valued reshape.
6 !
7 ! Contributed by Paul Thomas <[email protected]>
8 !
9 type t
10 integer :: i
11 end type t
12 type, extends(t) :: s
13 integer :: j
14 end type
15 class(t), allocatable :: a(:), aa(:), b(:,:), c(:,:,:), field(:,:,:)
16 integer, allocatable :: ishape(:), ii(:), ij(:)
17 logical :: la(2), lb(2,2), lc (4,2,2)
18 integer :: j, stop_flag
19
20 call check_spread
21 call check_pack
22 call check_unpack
23 call check_eoshift
24 call check_eoshift_dep
25 deallocate (a, aa, b, c, field, ishape, ii, ij)
26 contains
27 subroutine check_result_a (shift)
28 type (s), allocatable :: ss(:)
29 integer :: shift
30 select type (aa)
31 type is (s)
32 ss = eoshift (aa, shift = shift, boundary = aa(1), dim = 1)
33 ishape = shape (aa);
34 ii = ss%i
35 ij = ss%j
36 end select
37 if (any (ishape .ne. shape (a))) stop stop_flag + 1
38 select type (a)
39 type is (s)
40 if (any (a%i .ne. ii)) stop stop_flag + 2
41 if (any (a%j .ne. ij)) stop stop_flag + 3
42 class default
43 stop stop_flag + 4
44 end select
45 end
46
47 subroutine check_result
48 if (any (shape (c) .ne. ishape)) stop stop_flag + 1
49 select type (a)
50 type is (s)
51 if (any (a%i .ne. ii)) stop stop_flag + 2
52 if (any (a%j .ne. ij)) stop stop_flag + 3
53 class default
54 stop stop_flag + 4
55 end select
56 end
57
58 subroutine check_spread
59 stop_flag = 10
60 a = [(s(j,10*j), j = 1,2)]
61 b = spread (a, dim = 2, ncopies = 2)
62 c = spread (b, dim = 1, ncopies = 4)
63 a = reshape (c, [size (c)])
64 ishape = [4,2,2]
65 ii = [1,1,1,1,2,2,2,2,1,1,1,1,2,2,2,2]
66 ij = 10*[1,1,1,1,2,2,2,2,1,1,1,1,2,2,2,2]
67 call check_result
68 end
69
70 subroutine check_pack
71 stop_flag = 20
72 la = [.false.,.true.]
73 lb = spread (la, dim = 2, ncopies = 2)
74 lc = spread (lb, dim = 1, ncopies = 4)
75 a = pack (c, mask = lc)
76 ishape = shape (lc)
77 ii = [2,2,2,2,2,2,2,2]
78 ij = 10*[2,2,2,2,2,2,2,2]
79 call check_result
80 end
81
82 subroutine check_unpack
83 stop_flag = 30
84 a = [(s(j,10*j), j = 1,16)]
85 field = reshape ([(s(100*j,1000*j), j = 1,16)], shape(lc))
86 c = unpack (a, mask = lc, field = field)
87 a = reshape (c, [product (shape (lc))])
88 ishape = shape (lc)
89 ii = [100,200,300,400,1,2,3,4,900,1000,1100,1200,5,6,7,8]
90 ij = [1000,2000,3000,4000,10,20,30,40,9000,10000, 11000,12000,50,60,70,80]
91 call check_result
92 end
93
94 subroutine check_eoshift
95 stop_flag = 40
96 aa = a
97 a = eoshift (aa, shift = 3, boundary = aa(1), dim = 1)
98 call check_result_a (3)
99 end
100
101 subroutine check_eoshift_dep
102 stop_flag = 50
103 aa = a
104 a = eoshift (a, shift = -3, boundary = a(1), dim = 1)
105 call check_result_a (-3)
106 end
107 end