MCPcopy
hub / github.com/dask/dask / unique_no_structured_arr

Function unique_no_structured_arr

dask/array/routines.py:1710–1765  ·  view source on GitHub ↗
(
    ar, return_index=False, return_inverse=False, return_counts=False
)

Source from the content-addressed store, hash-verified

1708
1709
1710def unique_no_structured_arr(
1711 ar, return_index=False, return_inverse=False, return_counts=False
1712):
1713 # A simplified version of `unique`, that allows computing unique for array
1714 # types that don't support structured arrays (such as cupy.ndarray), but
1715 # can only compute values at the moment.
1716
1717 if (
1718 return_index is not False
1719 or return_inverse is not False
1720 or return_counts is not False
1721 ):
1722 raise ValueError(
1723 "dask.array.unique does not support `return_index`, `return_inverse` "
1724 "or `return_counts` with array types that don't support structured "
1725 "arrays."
1726 )
1727
1728 ar = ar.ravel()
1729
1730 args = [ar, "i"]
1731 meta = meta_from_array(ar)
1732
1733 out = blockwise(np.unique, "i", *args, meta=meta)
1734 out._chunks = tuple((np.nan,) * len(c) for c in out.chunks)
1735
1736 out_parts = [out]
1737
1738 name = f"unique-aggregate-{out.name}"
1739 dsk = {
1740 (name, 0): (
1741 (np.unique,)
1742 + tuple(
1743 (
1744 (np.concatenate, o.__dask_keys__())
1745 if hasattr(o, "__dask_keys__")
1746 else o
1747 )
1748 for o in out_parts
1749 )
1750 )
1751 }
1752
1753 dependencies = [o for o in out_parts if hasattr(o, "__dask_keys__")]
1754 graph = HighLevelGraph.from_collections(name, dsk, dependencies=dependencies)
1755 chunks = ((np.nan,),)
1756 out = Array(graph, name, chunks, meta=meta)
1757
1758 result = [out]
1759
1760 if len(result) == 1:
1761 result = result[0]
1762 else:
1763 result = tuple(result)
1764
1765 return result
1766
1767

Callers 1

uniqueFunction · 0.85

Calls 6

meta_from_arrayFunction · 0.90
ArrayClass · 0.90
from_collectionsMethod · 0.80
blockwiseFunction · 0.70
ravelMethod · 0.45
__dask_keys__Method · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…