It seems to run just fine, I get the output I need using l-k, the error occurs later when the loss is computed. I don’t think it’s negative, since the matrix is flipped using a[j:] (not sure about this part).