Find the unique elements in a given tensor. In addition, it optionally returns - the indices of the input tensor that give the unique values; - the indices of the unique tensor that reconstruct the input tensor; - the number of times each unique value comes up in the input tensor.
(
x: Expr,
sorted: bool | Expr = True,
return_index: bool | Expr = False,
return_inverse: bool | Expr = False,
return_counts: bool | Expr = False,
axis: int | Expr | None = None,
)
| 26 | |
| 27 | |
| 28 | def unique( |
| 29 | x: Expr, |
| 30 | sorted: bool | Expr = True, |
| 31 | return_index: bool | Expr = False, |
| 32 | return_inverse: bool | Expr = False, |
| 33 | return_counts: bool | Expr = False, |
| 34 | axis: int | Expr | None = None, |
| 35 | ) -> Expr: |
| 36 | """Find the unique elements in a given tensor. |
| 37 | In addition, it optionally returns |
| 38 | - the indices of the input tensor that give the unique values; |
| 39 | - the indices of the unique tensor that reconstruct the input tensor; |
| 40 | - the number of times each unique value comes up in the input tensor. |
| 41 | |
| 42 | Parameters |
| 43 | ---------- |
| 44 | x : relax.Expr |
| 45 | The input tensor. |
| 46 | |
| 47 | sorted : Union[bool, Expr] |
| 48 | Whether to sort the unique elements in ascending order before |
| 49 | returning as output. |
| 50 | |
| 51 | return_index : Union[bool, Expr] |
| 52 | Whether to return an additional tensor with indices for where elements in |
| 53 | the unique tensor come from the original input. |
| 54 | |
| 55 | return_inverse : Union[bool, Expr] |
| 56 | Whether to return an additional tensor with indices for where elements in |
| 57 | the original input ended up in the returned unique list. |
| 58 | |
| 59 | return_counts : Union[bool, Expr] |
| 60 | Whether to return an additional tensor with counts of each unique elements. |
| 61 | |
| 62 | axis : Optional |
| 63 | The dimension to apply unique. |
| 64 | If not specified, the unique values of the flattened input are returned. |
| 65 | |
| 66 | Returns |
| 67 | ------- |
| 68 | ret : relax.Expr |
| 69 | The created relax call with |
| 70 | """ |
| 71 | |
| 72 | if isinstance(sorted, bool): |
| 73 | sorted = PrimValue(sorted) |
| 74 | if isinstance(return_index, bool): |
| 75 | return_index = PrimValue(return_index) |
| 76 | if isinstance(return_inverse, bool): |
| 77 | return_inverse = PrimValue(return_inverse) |
| 78 | if isinstance(return_counts, bool): |
| 79 | return_counts = PrimValue(return_counts) |
| 80 | if axis is not None and isinstance(axis, int): |
| 81 | axis = PrimValue(axis) |
| 82 | return _ffi_api.unique( # type: ignore |
| 83 | x, sorted, return_index, return_inverse, return_counts, axis |
| 84 | ) |
| 85 |
nothing calls this directly
no test coverage detected
searching dependent graphs…