1! Program to test the MATMUL intrinsic
2program intrinsic_matmul
3   implicit none
4   integer, dimension(2, 3) :: a
5   integer, dimension(3, 2) :: b
6   integer, dimension(2) :: x
7   integer, dimension(3) :: y
8   integer, dimension(2, 2) :: r
9   integer, dimension(3) :: v
10   real, dimension (2,2) :: aa
11   real, dimension (4,2) :: cc
12
13   a = reshape((/1, 2, 2, 3, 3, 4/), (/2, 3/))
14   b = reshape((/1, 2, 3, 3, 4, 5/), (/3, 2/))
15   x = (/1, 2/)
16   y = (/1, 2, 3/)
17
18   r = matmul(a, b)
19   if (any(r .ne. reshape((/14, 20, 26, 38/), (/2, 2/)))) call abort
20
21   v = matmul(x, a)
22   if (any(v .ne. (/5, 8, 11/))) call abort
23
24   v(1:2) = matmul(a, y)
25   if (any(v(1:2) .ne. (/14, 20/))) call abort
26
27  aa = reshape((/ 1.0, 1.0, 0.0, 1.0/), shape(aa))
28  cc = 42.
29  cc(1:2,1:2) = matmul(aa, transpose(aa))
30  if (any(cc(1:2,1:2) .ne. reshape((/ 1.0, 1.0, 1.0, 2.0 /), (/2,2/)))) call abort
31  if (any(cc(3:4,1:2) .ne. 42.)) call abort
32end program
33