I want to check if a tensor contains nonzero elements. It does not matter to me how many nonzero elements there are. I currently do the following which is very inefficient for large tensors:
T.abs().sum().item() == 0
Is there a better way to do this in PyTorch? Like a function that stops iterating through the tensor as soon as it finds the first nonzero element?