2 ! { dg-options "-fno-inline" }
4 ! PRODUCT as initialization expression.
6 ! This test compares results of simplifier of PRODUCT
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_prod = PRODUCT (imatrix)
14 INTEGER, PARAMETER :: imatrix_prod_d1(4) = PRODUCT (imatrix, dim=1)
15 INTEGER, PARAMETER :: imatrix_prod_d2(2) = PRODUCT (imatrix, dim=2)
16 LOGICAL, PARAMETER :: i_equal_prod = ALL ([PRODUCT( imatrix_prod_d1 ) == PRODUCT ( imatrix_prod_d2 ), &
17 PRODUCT( imatrix_prod_d1 ) == imatrix_prod])
18 LOGICAL, PARAMETER :: i_empty_prod = PRODUCT(imatrix, mask=.FALSE.) == 1
20 REAL, PARAMETER :: rmatrix(2,4) = RESHAPE ([ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], [2, 4] )
21 REAL, PARAMETER :: rmatrix_prod = PRODUCT (rmatrix)
22 REAL, PARAMETER :: rmatrix_prod_d1(4) = PRODUCT (rmatrix, dim=1)
23 REAL, PARAMETER :: rmatrix_prod_d2(2) = PRODUCT (rmatrix, dim=2)
24 LOGICAL, PARAMETER :: r_equal_prod = ALL ([PRODUCT( rmatrix_prod_d1 ) == PRODUCT ( rmatrix_prod_d2 ), &
25 PRODUCT( rmatrix_prod_d1 ) == rmatrix_prod])
26 LOGICAL, PARAMETER :: r_empty_prod = PRODUCT(rmatrix, mask=.FALSE.) == 1.0
28 IF (.NOT. ALL ([i_equal_prod, i_empty_prod])) CALL abort()
29 IF (.NOT. ALL ([r_equal_prod, r_empty_prod])) CALL abort()
31 CALL ilib (imatrix, imatrix_prod)
32 CALL ilib_with_dim (imatrix, 1, imatrix_prod_d1)
33 CALL ilib_with_dim (imatrix, 2, imatrix_prod_d2)
34 CALL rlib (rmatrix, rmatrix_prod)
35 CALL rlib_with_dim (rmatrix, 1, rmatrix_prod_d1)
36 CALL rlib_with_dim (rmatrix, 2, rmatrix_prod_d2)
39 SUBROUTINE ilib (array, result)
40 INTEGER, DIMENSION(:,:), INTENT(in) :: array
41 INTEGER, INTENT(in) :: result
42 IF (PRODUCT(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 (PRODUCT (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(PRODUCT(array) - result) > 2e-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(PRODUCT (array, dim=dim) - result) > 2e-6)) CALL abort()