【发布时间】:2026-01-05 23:55:01
【问题描述】:
在 Fortran 中,可以对数组进行操作,但是如何将派生类型的索引也视为数组的一部分呢?代码会解释我最想做的事情:
type mytype
integer :: b(3,3)
real :: c(4)
endtype
integer :: a(3,3)
real :: d(2,4)
type(mytype) :: mat(2)
!do stuff so that 'mat' gets values
....
!usually one does this
a = matmul(mat(1)%b, transpose(mat(2)%b))
!multiplying two 3x3 matrices
!but how does one do this? Note the "array"
d = matmul(mat(:)%c, mat(:)%c)
我假设最后一行类似于与自身相乘的 2x4 矩阵。但是,当我尝试编译时,gfortran 抱怨
错误:不能指定两个或多个非零等级的零件参考
这可以在 Fortran 中实现吗?
【问题讨论】:
标签: arrays fortran derived-types