Coverage for math_utils.py : 29%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import torch
4def nanmean(v, *args, inplace=False, **kwargs):
5 """
6 Function that calculates mean of a tensor while removing missing values
8 From: https://github.com/pytorch/pytorch/issues/21987#issuecomment-539402619
9 """
10 if not inplace:
11 v = v.clone()
12 is_nan = torch.isnan(v)
13 v[is_nan] = 0
14 return v.sum(*args, **kwargs) / (~is_nan).float().sum(*args, **kwargs)