(
ar, return_index=False, return_inverse=False, return_counts=False
)
| 1660 | |
| 1661 | |
| 1662 | def unique_no_structured_arr( |
| 1663 | ar, return_index=False, return_inverse=False, return_counts=False |
| 1664 | ): |
| 1665 | # A simplified version of `unique`, that allows computing unique for array |
| 1666 | # types that don't support structured arrays (such as cupy.ndarray), but |
| 1667 | # can only compute values at the moment. |
| 1668 | |
| 1669 | if ( |
| 1670 | return_index is not False |
| 1671 | or return_inverse is not False |
| 1672 | or return_counts is not False |
| 1673 | ): |
| 1674 | raise ValueError( |
| 1675 | "dask.array.unique does not support `return_index`, `return_inverse` " |
| 1676 | "or `return_counts` with array types that don't support structured " |
| 1677 | "arrays." |
| 1678 | ) |
| 1679 | |
| 1680 | ar = ar.ravel() |
| 1681 | |
| 1682 | args = [ar, "i"] |
| 1683 | meta = meta_from_array(ar) |
| 1684 | |
| 1685 | out = blockwise(np.unique, "i", *args, meta=meta) |
| 1686 | out._chunks = tuple((np.nan,) * len(c) for c in out.chunks) |
| 1687 | |
| 1688 | out_parts = [out] |
| 1689 | |
| 1690 | name = "unique-aggregate-" + out.name |
| 1691 | dsk = { |
| 1692 | (name, 0): ( |
| 1693 | (np.unique,) |
| 1694 | + tuple( |
| 1695 | ( |
| 1696 | (np.concatenate, o.__dask_keys__()) |
| 1697 | if hasattr(o, "__dask_keys__") |
| 1698 | else o |
| 1699 | ) |
| 1700 | for o in out_parts |
| 1701 | ) |
| 1702 | ) |
| 1703 | } |
| 1704 | |
| 1705 | dependencies = [o for o in out_parts if hasattr(o, "__dask_keys__")] |
| 1706 | graph = HighLevelGraph.from_collections(name, dsk, dependencies=dependencies) |
| 1707 | chunks = ((np.nan,),) |
| 1708 | out = Array(graph, name, chunks, meta=meta) |
| 1709 | |
| 1710 | result = [out] |
| 1711 | |
| 1712 | if len(result) == 1: |
| 1713 | result = result[0] |
| 1714 | else: |
| 1715 | result = tuple(result) |
| 1716 | |
| 1717 | return result |
| 1718 | |
| 1719 |
no test coverage detected