Consider the following code which works as expected:

In [1]: import torch
In [2]: var = torch.autograd.Variable(torch.LongTensor(0))
In [3]: bool(var)
Out[3]: False

However, if I do the same with a non-empty variable:

In [4]: var = torch.autograd.Variable(torch.LongTensor(1))
In [5]: bool(var)
RuntimeError: bool value of Variable objects containing non-empty torch.LongTensor is ambiguous

It shows an error!
How to handle such scenarios when using an if/else condition etc?