Repository: pytorch
Issue: torch.histogram: Sum of PDFs is num of bins instead of 1
Labels: module: docs,triaged,module: sorting and selection

## 🐛 Bug

The description of the `torch.histogram` functions denotes for the `density` parameter the following:

> If False, the result will contain the count (or total weight) in each bin. If True, the result is the value of the probability density function over the bins, normalized such that the integral over the range of the bins is 1.

So I expected that the sum of the histogram is 1 if I set `density=True`. But it turns out that it is actually the number of bins. See the following code:

```python
A = torch.Tensor(np.array([
            [[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
            [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
            [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
        ]))
num_bins = 20
print(A.histogram(num_bins, density=True).hist.sum())
num_bins = 10
print(A.histogram(num_bins, density=True).hist.sum())
num_bins = 5
print(A.histogram(num_bins, density=True).hist.sum())
```
produces the following output
```
tensor(20.)
tensor(10.)
tensor(5.)
```

## To Reproduce

See code above

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

I expected the following output
```
tensor(1.)
tensor(1.)
tensor(1.)
```

## Environment

```
Collecting environment information...
PyTorch version: 1.10.0
Is debug build: False
CUDA used to build PyTorch: 11.3
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.3 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.31

Python version: 3.8.12 (default, Oct 12 2021, 13:49:34)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.4.0-90-generic-x86_64-with-glibc2.17
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration: 
GPU 0: NVIDIA GeForce RTX 3090
GPU 1: NVIDIA GeForce RTX 3090
GPU 2: NVIDIA GeForce RTX 3090
GPU 3: NVIDIA GeForce RTX 3090

Nvidia driver version: 495.29.05
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.21.2
[pip3] pytorch-msssim==0.2.1
[pip3] torch==1.10.0
[pip3] torchaudio==0.10.0
[pip3] torchvision==0.11.1
[conda] blas                      1.0                         mkl  
[conda] cudatoolkit               11.3.1               h2bc3f7f_2  
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] mkl                       2021.4.0           h06a4308_640  
[conda] mkl-service               2.4.0            py38h7f8727e_0  
[conda] mkl_fft                   1.3.1            py38hd3c417c_0  
[conda] mkl_random                1.2.2            py38h51133e4_0  
[conda] numpy                     1.21.2           py38h20f2e39_0  
[conda] numpy-base                1.21.2           py38h79a1101_0  
[conda] pytorch                   1.10.0          py3.8_cuda11.3_cudnn8.2.0_0    pytorch
[conda] pytorch-msssim            0.2.1                    pypi_0    pypi
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] torchaudio                0.10.0               py38_cu113    pytorch
[conda] torchvision               0.11.1               py38_cu113    pytorch
```

 - PyTorch Version (e.g., 1.0): 1.10.0
 - OS (e.g., Linux): Ubuntu 20.04.3 LTS (x86_64)
 - How you installed PyTorch (`conda`, `pip`, source): conda
 - Build command you used (if compiling from source): none
 - Python version: 3.8.12
 - CUDA/cuDNN version: 11.3
 - GPU models and configuration:
 - Any other relevant information:




cc @svekars @carljparker @brianjo @mruberry