Your solution is great in check whether a tensor is a subset of another tensor. However, it still has some limitation in checking the case if two different sub-tensors pointing to the same storage.
import torch
t = torch.rand((3,3))
t1 = t[0,:]
t2 = t[:,0]
same_storage(t1, t2)
>> False
However, if I change t1[0]
, t2
will change as well.