pytorch/torch/testing/_internal/opinfo/definitions
George Wigley a5051a9521 Update torch.masked.mean to upcast dtype for bool tensors (#139999)
When calling `torch.masked.mean(...)` with a boolean tensor, the dtype is inferred to be bool. When the mean is being computed, the sum operator is used. When the sum operator is used with dtype=torch.bool, the result is clamped to True (1) leading to an incorrect mean being calculated.

The below example shows how the incorrect result occurs:
```
a = torch.tensor([True, True])
count = torch.sum(torch.ones(a.shape, dtype=torch.int64)) # 2
total = torch.sum(a, dtype=torch.bool) # True (1)
mean = total / count # 0.5
```

This PR upcasts the dtype used for the sumation to int32 in the case of bool tensors allowing for the correct result to be computed.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/139999
Approved by: https://github.com/cpuhrsch
2025-01-08 10:35:19 +00:00
..
__init__.py
_masked.py Update torch.masked.mean to upcast dtype for bool tensors (#139999) 2025-01-08 10:35:19 +00:00
fft.py
linalg.py
nested.py [BE][Ez]: Fix docs recommending inefficient tensor op order (#144270) 2025-01-07 17:31:32 +00:00
signal.py
sparse.py Remove unused Python variables in torch/[b-z]* (#136963) 2024-10-19 16:45:22 +00:00
special.py [ATen][Native][Special] Hermite polynomial prematurely return NaN if n is high (#141955) 2024-12-18 08:30:08 +00:00