Define custom loss function in Pytorch

HI. I am a new user of Pytorch. I meet the challenge when I am trying to define my own loss function. My loss function is
$$ L(x,y) =\sum_{i,j=1}^n W[i,j]*max(0,x[i]-y[i]-x[j]+y[j]) $$
where W[i,j] is a known weight matrix. I am puzzled by this problem for a long time. :pensive: