Emulate fmin in torch 1.7.1
In the current version there exists torch.fmin Torch Documentation fimin
Unfortunately, my project relies on torch 1.7.1 and I can't upgrade. Is there another way to use min with NaNs in my tensor to emulate fmin. The NaNs are intended and are not a result of poor implementation. So I would like to keep them.

It's ugly but this works:
&gt;&gt;&gt; a = torch.tensor([2.2, float('nan'), 2.1, float('nan')])
&gt;&gt;&gt; b = torch.tensor([-9.3, 0.1, float('nan'), float('nan')])
&gt;&gt;&gt; c = torch.stack((a,b))
&gt;&gt;&gt; c[c.isnan()] = float('inf')
&gt;&gt;&gt; min_, idx = torch.min(c, dim=0)
&gt;&gt;&gt; min_[min_.isinf()] = float('nan')
&gt;&gt;&gt; min_
tensor([-9.3000,  0.1000,  2.1000,     nan])

