My question is similar to this one Multiply a 3D matrix with a 2D matrix. However, I’m coding in Fortran.
Say, if I have a RxSxT matrix A and an SxU matrix B, where R,S,T,U are integers, and I want to multiply A(:,:,0) with B. How can I do this with matmul? When I do something like
C(:,:,0) = matmul(A(:,:,0),B)
The compiler (gfortran) gives:
Warning:Array reference at (1) is out of bounds (0 < 1) in dimension 3
f951: internal compiler error: Segmentation fault
Is there a way around this?
Thanks.
EDIT: I should add that I’m actually transposing the second matrix. Say, A a RxSxT matrix and B a UxS matrix. Then
C(:,:,0) = matmul(B,transpose(A(:,:,0))
That transpose might be part of the problem. Does it convert A(i,j,k) to A(k,i,j)?
transpose (A(:,:,0)) should interchange the indices A(i,j,0) to A(j,i,0). A(:,:,0) is a rank two matrix.
The compiler should never crash, whether or not the input source code is correct. Are you using the latest version of gfortran? You could report this “internal compiler error: Segmentation fault” to the gfortran development team: http://gcc.gnu.org/wiki/GFortran#bugs