2 ! Check the fix for PR48462 in which the assignments involving matmul
3 ! seg faulted because a was automatically freed before the assignment.
5 ! Contributed by John Nedney <ortp21@gmail.com>
9 integer, parameter :: dp = kind(0.0d0)
10 real(kind=dp), allocatable :: delta(:,:)
16 ! Original reduced version from comment #2
19 real(kind=dp), allocatable :: a(:,:)
20 real(kind=dp), allocatable :: b(:,:)
26 b = reshape ([1d0, 0d0, 0d0, 0d0, 1d0, 0d0, 0d0, 0d0, 1d0], [3,3])
27 a = reshape ([1d0, 2d0, 3d0, 4d0, 5d0, 6d0, 7d0, 8d0, 9d0], [3,3])
29 a = matmul( matmul( a, b ), b )
30 delta = (a - reshape ([1d0, 2d0, 3d0, 4d0, 5d0, 6d0, 7d0, 8d0, 9d0], [3,3]))**2
31 if (any (delta > 1d-12)) call abort
32 if (any (lbound (a) .ne. [1, 1])) call abort
35 ! Check that all is well when the shape of 'a' changes.
38 real(kind=dp), allocatable :: a(:,:)
39 real(kind=dp), allocatable :: b(:,:)
41 b = reshape ([1d0, 1d0, 1d0], [3,1])
42 a = reshape ([1d0, 2d0, 3d0, 4d0, 5d0, 6d0, 7d0, 8d0, 9d0], [3,3])
44 a = matmul( a, matmul( a, b ) )
46 delta = (a - reshape ([198d0, 243d0, 288d0], [3,1]))**2
47 if (any (delta > 1d-12)) call abort
48 if (any (lbound (a) .ne. [1, 1])) call abort