What you want to achieve is entirely possible.



 rahul:

if (self.x.data > 0):


Here you are comparing a tensor against 0, which gives you a tensor (a python object). This object, when evaluated as a bool expression, is True-valued. So in fact it never goes to the second branch.