Ok. Finally tracked down the bug, so marking solved. (I’m not sure why some of the tensors above are showing as not nan, but it’s now theoretical, since fixing the bug means the problem above no longer manifests itself. The bug was that I had a tensor where some rows have data, and the other rows were undefined. I then multipled this by a binary mask, and added it to another tensor. However, zero times an undefined value gives nan whenever the undefined value is nan…).