Chunking a tensor with overlap

What is the best way to chunk up a tensor into fixed size chunks with a specified overlap?

So given a tensor T with a shape (for example) W=10,254, target chunksize of C=500 and overlap O=100 create a tensor Q with shape (B, C) where Q[0], Q[1], … is T[0:500], T[400:900], and Q[-1] is padded with a specified value.

You could use F.pad to pad a specific tensor in the specified dimensions as described in the docs.

tensor.unfold or F.unfold can be used to create overlapping patches of your tensor.