Unfortunately this won’t work. as x would contain tensors with different lengths, if I understand the use case correctly.
Could you zero-pad x and use lengths as a mask?
If not, could you explain your use case a bit, please?