I'm trying to grok the einops syntax for tensor reordering, but am somehow missing the point
If I have the following matrix:
mat = torch.randint(1, 10, (8,4))
I understand what the following command does:
rearrange(mat, '(h n) w -> (n h) w', n = 2)
But can't really wrap my head around the following ones:
rearrange(mat, '(n h) w -> (h n) w', n = 2)
rearrange(mat, '(n h) w -> (h n) w', n = 4)
Any help would be appreciated
are inversions of each other. If you can imagine what one does, second makes reverse transform
As for the latter, mat is 8x4
So you first split first dimension in 4x2 (below I ignore w dimension, because nothing special happens with it)
to
then you change order of axes to 2x4 (transpose)
then merge two dimensions into one
If you still don't feel how that works, take simpler examples like
etc. So that you could track movement of each element in the matrix