| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! PR119460: Scalar reduce was failing with ARRAY elements larger than |
| 4 |
! an address size. |
| 5 |
! |
| 6 |
! Contributed by Rainer Orth <[email protected]> |
| 7 |
! |
| 8 |
program test_reduce |
| 9 |
implicit none |
| 10 |
integer :: i |
| 11 |
integer, parameter :: dp = kind(1.0_8), extent = 4 |
| 12 |
|
| 13 |
real(dp) :: rarray(extent,extent,extent), rmat(extent,extent), & |
| 14 |
rvec (extent), rscl |
| 15 |
|
| 16 |
type :: t |
| 17 |
real(dp) :: field(extent) |
| 18 |
end type t |
| 19 |
|
| 20 |
type (t) :: tmat(extent, extent), tarray(extent), tscalar |
| 21 |
|
| 22 |
rarray = reshape ([(real(i, kind = dp), i = 1, size(rarray))], & |
| 23 |
shape (rarray)) |
| 24 |
|
| 25 |
rmat = reduce (rarray, add, dim = 1) |
| 26 |
if (any (rmat /= sum (rarray, 1))) stop 1 |
| 27 |
|
| 28 |
rmat = reduce (rarray, add, dim = 2) |
| 29 |
if (any (rmat /= sum (rarray, 2))) stop 2 |
| 30 |
|
| 31 |
rmat = reduce (rarray, add, dim = 3) |
| 32 |
if (any (rmat /= sum (rarray, 3))) stop 3 |
| 33 |
|
| 34 |
rscl = reduce (rarray, add) |
| 35 |
if (rscl /= sum (rarray)) stop 4 |
| 36 |
|
| 37 |
tmat%field(1) = rmat |
| 38 |
tarray = reduce (tmat, t_add, dim =1) |
| 39 |
rvec = reduce (rmat, add, dim = 1) |
| 40 |
if (any (tarray%field(1) /= rvec)) stop 5 |
| 41 |
|
| 42 |
tscalar = reduce (tmat, t_add) |
| 43 |
if (tscalar%field(1) /= sum (tmat%field(1))) stop 6 |
| 44 |
contains |
| 45 |
|
| 46 |
pure real(dp) function add (i, j) |
| 47 |
real(dp), intent(in) :: i, j |
| 48 |
add = i + j |
| 49 |
end function add |
| 50 |
|
| 51 |
pure type(t) function t_add (i, j) |
| 52 |
type(t), intent(in) :: i, j |
| 53 |
t_add%field(1) = i%field(1) + j%field(1) |
| 54 |
end function t_add |
| 55 |
|
| 56 |
end |