Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/torchmetrics/utilities/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,8 @@ def _flexible_bincount(x: Tensor) -> Tensor:
Number of occurrences for each unique element in x

"""
# make sure elements in x start from 0
x = x - x.min()
unique_x = torch.unique(x)

output = _bincount(x, minlength=torch.max(unique_x) + 1) # type: ignore[arg-type]
# remove zeros from output tensor
return output[unique_x]
unique_x, inverse_indices = torch.unique(x, return_inverse=True)
return _bincount(inverse_indices, minlength=len(unique_x)) # type: ignore[arg-type]


def allclose(tensor1: Tensor, tensor2: Tensor) -> bool:
Expand Down
Loading