multik icon indicating copy to clipboard operation
multik copied to clipboard

Add `pad` function

Open AlexandreBrown opened this issue 2 years ago • 1 comments

I would like to know how to pad using createAlignedNDArray.
From my understanding this function takes a list of lists and makes every list the max length and pads the remaining with zeros or whatever value you want (for each dim).
image

Example:
Let P be the size of each dims we want our final matrix to be with padding.
Let W and H be 2 sizes (different) that are less than P.
For the sake of this example let's say we have W< H < P.
Let a be an mk array of shape (W, H). Then applying createAlignedNDArray(a.toListD3(), 0.0) would give us a matrix of shape (H, H) padded with zeros.

While the name of the function seems correct, I'm interested in knowing if it's possible to use this function to transoform a into a matrix of size (P, P) instead.

Something like, we provide an mk array and can specify the desired padding for each dimensions.
See https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html

If it's possible with createAlignedNDArray then feel free to let me know.

AlexandreBrown avatar Nov 14 '22 19:11 AlexandreBrown