The title may be confusing, as I really don’t know how to name such operations. Basically, what I want to do is illustrated as follow:

suppose that I have a vector a= [2, 3, 4] and a length int 5;
I want to create a matrix
[[1,1,0,0,0],
[1,1,1,0,0],
[1,1,1,1,0]]

I can of course get this done with torch.ones(), F.pad and enumerating the elements in a. However, as I don’t want to transfer data between cpu and gpu, is there any other way to get this done?