Hello Yuchen!



 Yuchen_Mu:

will this code work?
Actually I verified that the final output, which is Final_M_norm_square, is the value that I want


I haven’t looked at your code in detail.
But from what you say, my understanding is that:


You are not using any complex tensors, so you don’t have
to worry about any pytorch complex issues.


Your calculation only uses pytorch tensor operations (i.e.,
you don’t switch over to something like numpy for part of
the calculation).


Your function gives you the correct “forward-pass” result.


So, yes, your code should work, it should work “for free” with
autograd, and backpropagation should work properly.
Best.
K. Frank