mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Revert D14605905: [pytorch][PR] Add return_counts to torch.unique
Differential Revision: D14605905 Original commit changeset: 555f5a12a8e2 fbshipit-source-id: c7874f5987893e956c022180a37763d88bba38db
This commit is contained in:
committed by
Facebook Github Bot
parent
bdd098c694
commit
66628f78b7
@ -374,8 +374,8 @@ def stft(input, n_fft, hop_length=None, win_length=None, window=None,
|
||||
return torch._C._VariableFunctions.stft(input, n_fft, hop_length, win_length, window, normalized, onesided)
|
||||
|
||||
|
||||
def unique(input, sorted=True, return_inverse=False, return_counts=False, dim=None):
|
||||
r"""Returns the unique elements of the input tensor.
|
||||
def unique(input, sorted=True, return_inverse=False, dim=None):
|
||||
r"""Returns the unique scalar elements of the input tensor as a 1-D tensor.
|
||||
|
||||
Arguments:
|
||||
input (Tensor): the input tensor
|
||||
@ -383,26 +383,18 @@ def unique(input, sorted=True, return_inverse=False, return_counts=False, dim=No
|
||||
before returning as output.
|
||||
return_inverse (bool): Whether to also return the indices for where
|
||||
elements in the original input ended up in the returned unique list.
|
||||
return_counts (bool): Whether to also return the counts for each unique
|
||||
element.
|
||||
dim (int): the dimension to apply unique. If ``None``, the unique of the
|
||||
flattened input is returned. default: ``None``
|
||||
|
||||
Returns:
|
||||
(Tensor, Tensor (optional) Tensor (optional)):
|
||||
A tensor or a tuple of tensors containing
|
||||
(Tensor, Tensor (optional)): A tensor or a tuple of tensors containing
|
||||
|
||||
- **output** (*Tensor*): the output list of unique scalar elements.
|
||||
- **inverse_indices** (*Tensor*): (optional) if
|
||||
:attr:`return_inverse` is True, there will be an additional
|
||||
returned tensor (same shape as input) representing the indices
|
||||
:attr:`return_inverse` is True, there will be a
|
||||
2nd returned tensor (same shape as input) representing the indices
|
||||
for where elements in the original input map to in the output;
|
||||
otherwise, this function will only return a single tensor.
|
||||
- **counts** (*Tensor*): (optional) if
|
||||
:attr:`return_counts` is True, there will be an additional
|
||||
returned tensor (same shape as output or output.size(dim),
|
||||
if dim was specified) representing the number of occurences
|
||||
for each unique value or tensor.
|
||||
|
||||
Example::
|
||||
|
||||
@ -427,26 +419,20 @@ def unique(input, sorted=True, return_inverse=False, return_counts=False, dim=No
|
||||
|
||||
"""
|
||||
if dim is not None:
|
||||
output, inverse_indices, counts = torch._unique_dim(
|
||||
output, inverse_indices = torch._unique_dim(
|
||||
input,
|
||||
dim,
|
||||
sorted=sorted,
|
||||
return_inverse=return_inverse,
|
||||
return_counts=return_counts
|
||||
return_inverse=return_inverse
|
||||
)
|
||||
else:
|
||||
output, inverse_indices, counts = torch._unique(
|
||||
output, inverse_indices = torch._unique(
|
||||
input,
|
||||
sorted=sorted,
|
||||
return_inverse=return_inverse,
|
||||
return_counts=return_counts
|
||||
)
|
||||
if return_inverse and return_counts:
|
||||
return output, inverse_indices, counts
|
||||
elif return_inverse:
|
||||
if return_inverse:
|
||||
return output, inverse_indices
|
||||
elif return_counts:
|
||||
return output, counts
|
||||
else:
|
||||
return output
|
||||
|
||||
|
Reference in New Issue
Block a user