albanD:

Note as well that tom’s code will create undestructible ref cycle and will leak memory on top of being very wrong 
The original purpose of save_for_backward() is actually to avoid this cycle 


Touché! But you have NaNs if b is 0.
More seriously, I’d probably throw cloning.
Best regards
Thomas