Numpy has a nan_to_num function, which replaces nan, inf, and -inf with three arbitrary constants (usually zero, something large, and some large negative number). Is there an equivalent in pytorch? If not, how would I construct my own, without assignment operators that would break the gradient; would I have to assemble something element-by-element and use torch.cat, or is there some other solution? I am fine with the fact that all replaced elements would have a gradient of 0.