Fortran数组排名为matmul内部 [英] Fortran array rank for matmul intrinsic
本文介绍了Fortran数组排名为matmul内部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下链接 https://gcc.gnu。 org / onlinedocs / gcc-5.4.0 / gfortran / MATMUL.html 明确指出,gfortran期望输入 matmul
的矩阵为1或2。下面的片段不会编译:
程序暂存
real(kind = 8):: A(10)=( / 0,1,2,3,4,5,6,7,8,9 /)
real(kind = 8):: B(10)=(/ 0,1,2,3,4 ,5,6,7,8,9 /)
real(kind = 8):: C(10,10)
print *,等级(A),等级(B)
C = matmul(A,B)
结束程序暂存
gfortran给出错误:
$ gfortran scratch.f90
scratch.f90:6:13:
C = matmul(A,B)
1
错误:(1)处的'matmul'内部的'matrix_b'参数必须是2级
我的gfortran是5.4.0(与上面的链接兼容)。我做的事情真的很愚蠢吗?
解决方案
您可以使用 RESHAPE
c $ c> MATMUL 会像:
程序暂存
real(kind = 8 ):: A(10)=(/ 0,1,2,3,4,5,6,7,8,9 /)
real(kind = 8):: B(10)=(/ 0,1,2,3,4,5,6,7,8,9 /)
real(kind = 8):: C(10,10)
print *,rank(A) ,等级(B)
C = matmul(RESHAPE(A,(/ 10,1 /)),RESHAPE(B,(/ 1,10 /)))
WRITE(*,(10F7 .2))C
结束程序暂存
The following link https://gcc.gnu.org/onlinedocs/gcc-5.4.0/gfortran/MATMUL.html clearly states that gfortran expects matrices input to matmul
to be of rank 1 OR 2. However the following snippet wont compile:
Program scratch
real(kind=8) :: A(10)=(/0,1,2,3,4,5,6,7,8,9/)
real(kind=8) :: B(10)=(/0,1,2,3,4,5,6,7,8,9/)
real(kind=8) :: C(10,10)
print *,rank(A),rank(B)
C=matmul(A,B)
End Program scratch
gfortran gives the error:
$gfortran scratch.f90
scratch.f90:6:13:
C=matmul(A,B)
1
Error: ‘matrix_b’ argument of ‘matmul’ intrinsic at (1) must be of rank 2
My gfortran is 5.4.0 (compatible with the link above). Am I doing something really stupid?
解决方案
You can use RESHAPE
to get them into a form MATMUL
will like:
Program scratch
real(kind=8) :: A(10)=(/0,1,2,3,4,5,6,7,8,9/)
real(kind=8) :: B(10)=(/0,1,2,3,4,5,6,7,8,9/)
real(kind=8) :: C(10,10)
print *,rank(A),rank(B)
C = matmul( RESHAPE(A,(/10,1/)), RESHAPE(B,(/1,10/)) )
WRITE(*,"(10F7.2)") C
End Program scratch
这篇关于Fortran数组排名为matmul内部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文