2 ! { dg-options "-fno-inline" }
4 ! SUM as initialization expression.
6 ! This test compares results of simplifier of SUM
7 ! with the corresponding inlined or library routine(s).
12 INTEGER, PARAMETER :: imatrix(2,4) = RESHAPE ([ 1, 2, 3, 4, 5, 6, 7, 8 ], [2, 4] )
13 INTEGER, PARAMETER :: imatrix_sum = SUM (imatrix)
14 INTEGER, PARAMETER :: imatrix_sum_d1(4) = SUM (imatrix, dim=1)
15 INTEGER, PARAMETER :: imatrix_sum_d2(2) = SUM (imatrix, dim=2)
16 LOGICAL, PARAMETER :: i_equal_sum = ALL ([SUM( imatrix_sum_d1 ) == SUM ( imatrix_sum_d2 ), &
17 SUM( imatrix_sum_d1 ) == imatrix_sum])
18 LOGICAL, PARAMETER :: i_empty_sum = SUM(imatrix, mask=.FALSE.) == 0
20 REAL, PARAMETER :: rmatrix(2,4) = RESHAPE ([ 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 ], [2, 4] )
21 REAL, PARAMETER :: rmatrix_sum = SUM (rmatrix)
22 REAL, PARAMETER :: rmatrix_sum_d1(4) = SUM (rmatrix, dim=1)
23 REAL, PARAMETER :: rmatrix_sum_d2(2) = SUM (rmatrix, dim=2)
24 LOGICAL, PARAMETER :: r_equal_sum = ALL ([SUM( rmatrix_sum_d1 ) == SUM ( rmatrix_sum_d2 ), &
25 SUM( rmatrix_sum_d1 ) == rmatrix_sum])
26 LOGICAL, PARAMETER :: r_empty_sum = SUM(rmatrix, mask=.FALSE.) == 0.0
28 IF (.NOT. ALL ([i_equal_sum, i_empty_sum])) CALL abort()
29 IF (.NOT. ALL ([r_equal_sum, r_empty_sum])) CALL abort()
31 CALL ilib (imatrix, imatrix_sum)
32 CALL ilib_with_dim (imatrix, 1, imatrix_sum_d1)
33 CALL ilib_with_dim (imatrix, 2, imatrix_sum_d2)
34 CALL rlib (rmatrix, rmatrix_sum)
35 CALL rlib_with_dim (rmatrix, 1, rmatrix_sum_d1)
36 CALL rlib_with_dim (rmatrix, 2, rmatrix_sum_d2)
39 SUBROUTINE ilib (array, result)
40 INTEGER, DIMENSION(:,:), INTENT(in) :: array
41 INTEGER, INTENT(in) :: result
42 IF (SUM(array) /= result) CALL abort()
45 SUBROUTINE ilib_with_dim (array, dim, result)
46 INTEGER, DIMENSION(:,:), INTENT(in) :: array
47 INTEGER, INTENT(iN) :: dim
48 INTEGER, DIMENSION(:), INTENT(in) :: result
49 IF (ANY (SUM (array, dim=dim) /= result)) CALL abort()
52 SUBROUTINE rlib (array, result)
53 REAL, DIMENSION(:,:), INTENT(in) :: array
54 REAL, INTENT(in) :: result
55 IF (ABS(SUM(array) - result) > 4e-6) CALL abort()
58 SUBROUTINE rlib_with_dim (array, dim, result)
59 REAL, DIMENSION(:,:), INTENT(in) :: array
60 INTEGER, INTENT(iN) :: dim
61 REAL, DIMENSION(:), INTENT(in) :: result
62 IF (ANY (ABS(SUM (array, dim=dim) - result) > 4e-6)) CALL abort()