更新时间:2022-06-21 21:31:25
尝试
z = x * spread(y,1,3)
,如果那行不通(这台计算机上没有Fortran,所以我没有检查过),则摆弄 spread
,直到它生效为止.实际上,您可能希望将 3
替换为 size(x,1)
等.
and if that doesn't work (no Fortran on this computer so I haven't checked) fiddle around with spread
until it does. In practice you'll probably want to replace the 3
by size(x,1)
or suchlike.
我希望这会导致编译器创建临时数组.而且我希望能够轻松找到在问题中表现不佳的显式循环方案的情况.纯净的"单线通常在时间和空间上都有成本.经常使用的经过验证的Fortran显式循环方法是一种.
I expect that this will cause the compiler to create temporary arrays. And I expect it will be easy to find situations where it underperforms the explicit looping scheme in the question. 'neat' one-liners often have a cost in both time and space. And often tried-and-trusted Fortran approach of explicit looping is the one to go with.