OSDN Git Service

fortran/
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gfortran.dg / matmul_3.f90
1 ! { dg-do run }\r
2 ! Check the fix for PR28005, in which the mechanism for dealing\r
3 ! with matmul (transpose (a), b) would cause wrong results for\r
4 ! matmul (a(i, 1:n), b(1:n, 1:n)).\r
5 !\r
6 ! Based on the original testcase contributed by\r
7 ! Tobias Burnus  <tobias.burnus@physik.fu-berlin.de>\r
8 !   \r
9    implicit none\r
10    integer, parameter         ::  nmax = 3\r
11    integer                    ::  i, n = 2\r
12    integer, dimension(nmax,nmax) ::  iB=0 , iC=1\r
13    integer, dimension(nmax,nmax) ::  iX1=99, iX2=99, iChk\r
14    iChk = reshape((/30,66,102,36,81,126,42,96,150/),(/3,3/))\r
15 \r
16 ! This would give 3, 3, 99\r
17    iB = reshape((/1 ,3 ,0 ,2 ,5 ,0 ,0 ,0 ,0 /),(/3,3/))\r
18    iX1(1:n,1) = matmul( iB(2,1:n),iC(1:n,1:n) )\r
19 \r
20 ! This would give 4, 4, 99\r
21    ib(3,1) = 1\r
22    iX2(1:n,1) = matmul( iB(2,1:n),iC(1:n,1:n) )\r
23 \r
24 ! Whereas, we should have 8, 8, 99\r
25    if (any (iX1(1:n,1) .ne. (/8, 8, 99/))) call abort ()\r
26    if (any (iX1 .ne. iX2)) call abort ()\r
27 \r
28 ! Make sure that the fix does not break transpose temporaries.\r
29    iB = reshape((/(i, i = 1, 9)/),(/3,3/))\r
30    ic = transpose (iB)\r
31    iX1 = transpose (iB)\r
32    iX1 = matmul (iX1, iC)\r
33    iX2 = matmul (transpose (iB), iC)\r
34    if (any (iX1 .ne. iX2)) call abort ()\r
35    if (any (iX1 .ne. iChk)) call abort ()\r
36 end\r