Yes you are right, my bad.
view(2,2) applied on x is causing the problem. This makes x a non-leaf variable.
If that is removed the code works.
You may also add one more step which applies view operation on x, then also it will work.