Solved by ptrblck in post #6 
              
              
                Yes, you could do this and post the executable code snippet here in case you get stuck. 
Your current code is not execuable, i.e. I cannot just copy-paste it, run it, and reproduce the issue, which would be possible if you use random tensors and post the missing parts of the code.