How can I sum parts of pytorch tensor of variable sizes?
Let's consider example.
I have a tensor of size (10, 3).
I want to sum first 3 rows, next 2 rows and 5 next rows by 0 axis.
For example from:
t = torch.ones([10, 3])

I want to get:
[
    [3.0, 3.0, 3.0],
    [2.0, 2.0, 2.0],
    [5.0, 5.0, 5.0],
]

I want to specify a tensor with values and a tensor with part sizes and possibly axis and get a tensor summed along this axis by parts of specified sizes.
How can I achieve that?

Following the great idea of @ben-grossmann I modified it a little to use sparse tensor and make it more efficient. And implemented it as a function:
def sum_var_parts(t, lens):
    t_size_0 = t.size(0)
    ind_x = torch.repeat_interleave(torch.arange(lens.size(0)), lens)
    indices = torch.cat(
        [
            torch.unsqueeze(ind_x, dim=0),
            torch.unsqueeze(torch.arange(t_size_0), dim=0)
        ],
        dim=0
    )
    M = torch.sparse_coo_tensor(
        indices,
        torch.ones(t_size_0, dtype=torch.float32),
        size=[lens.size(0), t_size_0]
    )
    return M @ t

