How to use numpy einsum_path result?
Do some time tests
path = np.einsum_path('oij,imj,mjkn,lnk,plk->op',phi,B,Suu,B,phi)
np.einsum('oij,imj,mjkn,lnk,plk->op',phi,B,Suu,B,phi, optimize=False)
np.einsum('oij,imj,mjkn,lnk,plk->op',phi,B,Suu,B,phi, optimize=True)
np.einsum('oij,imj,mjkn,lnk,plk->op',phi,B,Suu,B,phi, optimize=path[0])
In my testing the second 2 run at the same speed. For a small problem optimize=False
is faster, presumably because the analysis and rearranging takes time. For a large problem, with a larger theoretical speedup, the actual speedup for True
can be larger than than theory. Presumably memory management is slowing down the False
case.
The theoretical speedup
is just that, an estimate based just on FLOPS count. That will be true only to the extent that FLOPS dominate the calculation.
You could also time the path
calc. The size of the problem will determine whether its time is a small or large part of the total time.