1! RUN: %python %S/test_folding.py %s %flang_fc1 2! Tests folding of FINDLOC, MAXLOC, & MINLOC 3module m1 4 integer, parameter :: ia1(2:6) = [1, 2, 3, 2, 1] 5 integer, parameter :: ia2(2:3,2:4) = reshape([1, 2, 3, 3, 2, 1], shape(ia2)) 6 integer, parameter :: ia3(2,0,2) = 0 ! middle dimension has zero extent 7 8 logical, parameter :: test_fi1a = all(findloc(ia1, 1) == 1) 9 logical, parameter :: test_fi1ar = rank(findloc(ia1, 1)) == 1 10 logical, parameter :: test_fi1ak = kind(findloc(ia1, 1, kind=2)) == 2 11 logical, parameter :: test_fi1ad = findloc(ia1, 1, dim=1) == 1 12 logical, parameter :: test_fi1adr = rank(findloc(ia1, 1, dim=1)) == 0 13 logical, parameter :: test_fi1b = all(findloc(ia1, 1, back=.true.) == 5) 14 logical, parameter :: test_fi1c = all(findloc(ia1, 2, mask=[.false., .false., .true., .true., .true.]) == 4) 15 16 logical, parameter :: test_fi2a = all(findloc(ia2, 1) == [1, 1]) 17 logical, parameter :: test_fi2ar = rank(findloc(ia2, 1)) == 1 18 logical, parameter :: test_fi2b = all(findloc(ia2, 1, back=.true.) == [2, 3]) 19 logical, parameter :: test_fi2c = all(findloc(ia2, 2, mask=reshape([.false., .false., .true., .true., .true., .false.], shape(ia2))) == [1, 3]) 20 logical, parameter :: test_fi2d = all(findloc(ia2, 1, dim=1) == [1, 0, 2]) 21 logical, parameter :: test_fi2e = all(findloc(ia2, 1, dim=2) == [1, 3]) 22 23 logical, parameter :: test_xi1a = all(maxloc(ia1) == 3) 24 logical, parameter :: test_xi1ar = rank(maxloc(ia1)) == 1 25 logical, parameter :: test_xi1ak = kind(maxloc(ia1, kind=2)) == 2 26 logical, parameter :: test_xi1ad = maxloc(ia1, dim=1) == 3 27 logical, parameter :: test_xi1adr = rank(maxloc(ia1, dim=1)) == 0 28 logical, parameter :: test_xi1b = all(maxloc(ia1, back=.true.) == 3) 29 logical, parameter :: test_xi1c = all(maxloc(ia1, mask=[.false., .true., .false., .true., .true.]) == 2) 30 logical, parameter :: test_xi1d = all(maxloc(ia1, mask=[.false., .true., .false., .true., .true.], back=.true.) == 4) 31 32 logical, parameter :: test_xi2a = all(maxloc(ia2) == [1, 2]) 33 logical, parameter :: test_xi2ar = rank(maxloc(ia2)) == 1 34 logical, parameter :: test_xi2b = all(maxloc(ia2, back=.true.) == [2, 2]) 35 logical, parameter :: test_xi2c = all(maxloc(ia2, mask=reshape([.false., .true., .true., .true., .true., .true.], shape(ia2))) == [1, 2]) 36 logical, parameter :: test_xi2d = all(maxloc(ia2, mask=reshape([.false., .true., .true., .true., .true., .true.], shape(ia2)), back=.true.) == [2, 2]) 37 logical, parameter :: test_xi2e = all(maxloc(ia2, dim=1) == [2, 1, 1]) 38 logical, parameter :: test_xi2f = all(maxloc(ia2, dim=1, back=.true.) == [2, 2, 1]) 39 logical, parameter :: test_xi2g = all(maxloc(ia2, dim=2) == [2, 2]) 40 41 logical, parameter :: test_ni1a = all(minloc(ia1) == 1) 42 logical, parameter :: test_ni1ar = rank(minloc(ia1)) == 1 43 logical, parameter :: test_ni1ak = kind(minloc(ia1, kind=2)) == 2 44 logical, parameter :: test_ni1ad = minloc(ia1, dim=1) == 1 45 logical, parameter :: test_ni1adr = rank(minloc(ia1, dim=1)) == 0 46 logical, parameter :: test_ni1b = all(minloc(ia1, back=.true.) == 5) 47 logical, parameter :: test_ni1c = all(minloc(ia1, mask=[.false., .true., .true., .true., .false.]) == 2) 48 logical, parameter :: test_ni1d = all(minloc(ia1, mask=[.false., .true., .true., .true., .false.], back=.true.) == 4) 49 50 logical, parameter :: test_ni2a = all(minloc(ia2) == [1, 1]) 51 logical, parameter :: test_ni2ar = rank(minloc(ia2)) == 1 52 logical, parameter :: test_ni2b = all(minloc(ia2, back=.true.) == [2, 3]) 53 logical, parameter :: test_ni2c = all(minloc(ia2, mask=reshape([.false., .true., .true., .false., .true., .false.], shape(ia2))) == [2, 1]) 54 logical, parameter :: test_ni2d = all(minloc(ia2, mask=reshape([.false., .true., .true., .false., .true., .false.], shape(ia2)), back=.true.) == [1, 3]) 55 logical, parameter :: test_ni2e = all(minloc(ia2, dim=1) == [1, 1, 2]) 56 logical, parameter :: test_ni2f = all(minloc(ia2, dim=1, back=.true.) == [1, 2, 2]) 57 logical, parameter :: test_ni2g = all(minloc(ia2, dim=2) == [1, 3]) 58 59 logical, parameter :: test_xi3a = all(maxloc(ia3) == [0,0,0]) 60 logical, parameter :: test_xi3b = all(maxloc(ia3, back=.true.) == [0,0,0]) 61 logical, parameter :: test_xi3c = all(maxloc(ia3, dim=2) == reshape([0,0,0,0],shape=[2,2])) 62 logical, parameter :: test_xi3d = all(maxloc(ia3, dim=2, back=.true.) == reshape([0,0,0,0],shape=[2,2])) 63 64 character(1), parameter :: a(4) = ['a', 'b', 'a', 'b'] 65 logical, parameter :: test_char1 = all(maxloc(a).eq.[2]) 66 logical, parameter :: test_char2 = all(minloc(a).eq.[1]) 67 logical, parameter :: test_char3 = all(maxloc(a, back=.true.).eq.[4]) 68 logical, parameter :: test_char4 = all(minloc(a, back=.true.).eq.[3]) 69 70 ! Check with scalar MASK= 71 logical, parameter:: test_mia1_mt = all(minloc(ia1, mask=.true.) == 1) 72 logical, parameter:: test_mia1_mtd = all(minloc(ia1, mask=.true., dim=1) == [1]) 73 logical, parameter:: test_xia1_mt = all(maxloc(ia1, mask=.true.) == 3) 74 logical, parameter:: test_xia1_mtd = all(maxloc(ia1, mask=.true., dim=1) == [3]) 75 logical, parameter:: test_fia1_mt = all(findloc(ia1, 1, mask=.true.) == 1) 76 logical, parameter:: test_fia1_mtd = all(findloc(ia1, 1, mask=.true., dim=1) == [1]) 77 78 logical, parameter:: test_mia1_mf = all(minloc(ia1, mask=.false.) == 0) 79 logical, parameter:: test_mia1_mfd = all(minloc(ia1, mask=.false., dim=1) == [0]) 80 logical, parameter:: test_xia1_mf = all(maxloc(ia1, mask=.false.) == 0) 81 logical, parameter:: test_xia1_mfd = all(maxloc(ia1, mask=.false., dim=1) == [0]) 82 logical, parameter:: test_fia1_mf = all(findloc(ia1, 1, mask=.false.) == 0) 83 logical, parameter:: test_fia1_mfd = all(findloc(ia1, 1, mask=.false., dim=1) == [0]) 84end module 85