Solved by Matthias_Moller in post #3 
              
              
                I looked into the above code once more and found out that torch::reshape can be replaced by view(...). The above two code snippets then look as follows: 
return torch::stack( { base[k], base[k+1] } ).view( {1,2} );

and 
torch::Tensor zero = torch::zeros(1);
return torch::stack( { base[k], base[k+1]…