-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
EHN: cluster: JAX support (non-jitted) #22255
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,8 +137,8 @@ def whiten(obs, check_finite=True): | |
obs = _asarray(obs, check_finite=check_finite, xp=xp) | ||
std_dev = xp.std(obs, axis=0) | ||
zero_std_mask = std_dev == 0 | ||
if xp.any(zero_std_mask): | ||
std_dev[zero_std_mask] = 1.0 | ||
std_dev = xpx.at(std_dev, zero_std_mask).set(1.0) | ||
if check_finite and xp.any(zero_std_mask): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fails on jax.jit with an error message that's not not useful to final scipy users, unless you explicitly pass |
||
warnings.warn("Some columns have standard deviation zero. " | ||
"The values of these columns will not change.", | ||
RuntimeWarning, stacklevel=2) | ||
|
@@ -607,15 +607,16 @@ def _kpp(data, k, rng, xp): | |
|
||
for i in range(k): | ||
if i == 0: | ||
init[i, :] = data[rng_integers(rng, data.shape[0]), :] | ||
|
||
data_idx = rng_integers(rng, data.shape[0]) | ||
else: | ||
D2 = cdist(init[:i,:], data, metric='sqeuclidean').min(axis=0) | ||
probs = D2/D2.sum() | ||
cumprobs = probs.cumsum() | ||
r = rng.uniform() | ||
cumprobs = np.asarray(cumprobs) | ||
init[i, :] = data[np.searchsorted(cumprobs, r), :] | ||
data_idx = np.searchsorted(cumprobs, r) | ||
|
||
init = xpx.at(init)[i, :].set(data[data_idx, :]) | ||
|
||
if ndim == 1: | ||
init = init[:, 0] | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails on jax.jit. My current intention is to change jax.jit itself to special-case
arr.at[idx].set(value)
when idx is a boolean mask and value is a scalar, so that it can be rewritten asjnp.where(idx, value, arr)
. Failing that, I can implement the same special case in array-api-extra.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think changing
jax.jit
itself is a viable path here – I wouldn't suggest starting on that route.It might be viable to make
arr.at[idx].set(value)
lower tolax.select
rather thanlax.scatter
in the specific case of a booleanidx
. I've tried that in the past, but it's really tricky to properly handle all corner cases of broadcasted and/or multi-dimensional indices, correctly implementing autodiff and batching rules, etc.The easiest thing would probably be to do this at the level of
xp.at
, though boolean indices were specifically excluded from the initial discussions there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a (partial, non-functioning) PR I could start from?