MCPcopy Create free account
hub / github.com/dask/dask / unique_no_structured_arr

Function unique_no_structured_arr

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

Source from the content-addressed store, hash-verified

1660
1661
1662def 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

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