Mic*_*l A 5 fortran gfortran fortran2003
我有一个简单的fortran函数来计算Kronecker产品:
function kron(A, B)
implicit none
real, intent(in) :: A(:, :), B(:, :)
integer :: i, j, ma, na, mb, nb
real, dimension(:, :) :: kron
ma = ubound(A, 1)
na = ubound(A, 2)
mb = ubound(b, 1)
nb = ubound(b, 2)
forall(i=1:ma, j=1:na)
kron(mb*(i-1)+1:mb*i, nb*(j-1)+1:nb*j) = A(i,j)*B
end forall
end function kron
Run Code Online (Sandbox Code Playgroud)
它在一个模块中,但是当我编译它时gfortran -static -ffree-form -std=f2003 -Wall,我得到这些错误:
function kron(A, B)
1
Error: Array 'kron' at (1) cannot have a deferred shape
Run Code Online (Sandbox Code Playgroud)
是否发生此错误是因为您应该知道要事先返回的数组的大小?
这正是错误告诉你的:kron必须有一个明确的形状.如果您不想事先传递数组大小,则必须定义kron为
real, dimension(lbound(a,dim=1):ubound(a,dim=1),&
lbound(a,dim=2):ubound(a,dim=2)) :: kron
Run Code Online (Sandbox Code Playgroud)
使用上面这个特定的显式声明可以在gfortran 4.6.3上为我编译.