I do not think you can do this as tensor.unfold depending on some criteria creates another dimension like .unsqueeze(0) and because of that .view and .permute will no longer be valid due to number of dimension mismatch.



 trougnouf:

“x.unfold(2, 2, 2)[0].unfold(2,” to “x.unfold(2, 2, 2).unfold(3,”


Actually, I have never thought of generalizing fold and unfold method due to its tricky behavior (or at least my bad understanding).