-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calculate number of unique values in a lazy array #834
Comments
To brainstorm a potential solution, assuming there is no easier solution here, could we:
I suppose (2) would require a resolution to #748 (comment) first though, given that I don't like the idea of array-api-compat having to track all the possible ways to materialise for the finitely many supported libraries:
|
The inspection API already has a way of determining if a library supports data-dependent output shapes https://data-apis.org/array-api/draft/API_specification/generated/array_api.info.capabilities.html#array_api.info.capabilities |
The issue isn't So the only library with an issue is Dask. Rewriting the code to |
@lucascolley I think there's nothing to do or change for the standard here - can we close this? |
Yep. I suppose the recommendation going forwards will be "if you need to call |
How is |
The title of this issue - to calculate the number of unique values, hence |
I guess it's here https://github.com/scipy/scipy/blob/424708ed018cae6b6584d7d992940fd39f2ebcc0/scipy/cluster/hierarchy.py#L4157 n_clusters = int(xp.unique_values(T).shape[0])
n_obs = int(Z.shape[0] + 1)
L = np.zeros(n_clusters, dtype=np.int32)
M = np.zeros(n_clusters, dtype=np.int32)
Z = np.asarray(Z)
T = np.asarray(T, dtype=np.int32)
s = _hierarchy.leaders(Z, T, L, M, n_clusters, n_obs)
if s >= 0:
raise ValueError(('T is not a valid assignment vector. Error found '
'when examining linkage node %d (< 2n-1).') % s)
L, M = xp.asarray(L), xp.asarray(M)
return (L, M) |
To spell it out: in the code above, |
An example from SciPy:
We calculate the number of unique values in
T
via a data-dependent shape. As noted in the spec forunique_values
, the function may be omitted by lazy libraries due to the data-dependent shape.Is there an alternative in the standard which works with lazy arrays? If not, can there be?
x-ref gh-748, data-apis/array-api-compat#175
The text was updated successfully, but these errors were encountered: