pytorch
555c83d0 - Added a UserWarning when using torch.{std,var,std_mean,std_var} with dof<=0 (#109824)

Commit
1 year ago
Added a UserWarning when using torch.{std,var,std_mean,std_var} with dof<=0 (#109824) Fixes #109696. This PR adds a `UserWarning` when calling - `torch.var` - `torch.var_mean` - `torch.std` - `torch.std_mean` with an effective `dof<=0`. Until now, only `torch.cov` warned about this. The code also handles edge cases, such as `torch.empty` ``` >>> import torch; torch.std_mean(torch.empty(0), correction=0) <stdin>:1: UserWarning: std_mean(): degrees of freedom is <= 0 (Triggered internally at /app/aten/src/ATen/native/ReduceOps.cpp:1671.) (tensor(nan), tensor(nan)) ``` multi-dim reductions ``` >>> import torch; torch.std_mean(torch.empty(10, 30, 20, 50), correction=600, dim=(1, 2)) <stdin>:1: UserWarning: std_mean(): degrees of freedom is <= 0 (Triggered internally at /app/aten/src/ATen/native/ReduceOps.cpp:1671.) [... snip ...] ``` and a negative `correction`. ``` >>> import torch; torch.std_mean(torch.randn(0), correction=-5) (tensor(nan), tensor(nan)) ``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/109824 Approved by: https://github.com/soulitzer
Author
Committer
Parents
Loading