-
Notifications
You must be signed in to change notification settings - Fork 21
ENH: add nanmin
#804
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
base: main
Are you sure you want to change the base?
ENH: add nanmin
#804
Changes from all commits
6709082
214a7a3
9bd01fc
c6f41f1
23a1dd7
236f11d
d98cfa5
4f261f7
7822f6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| isin | ||
| kron | ||
| nan_to_num | ||
| nanmin | ||
| nunique | ||
| one_hot | ||
| pad | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| "isin", | ||
| "kron", | ||
| "nan_to_num", | ||
| "nanmin", | ||
| "nunique", | ||
| "one_hot", | ||
| "pad", | ||
|
|
@@ -823,3 +824,24 @@ def unravel_index(indices: Array, shape: tuple[int, ...], /) -> tuple[Array, ... | |
| coords.append(indices % dim) | ||
| indices = indices // dim | ||
| return tuple(reversed(coords)) | ||
|
|
||
|
|
||
| def nanmin( # numpydoc ignore=PR01,RT01 | ||
|
Member
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. whereabouts did you take this implementation from?
Contributor
Author
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.
Member
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. would be good to check the history there
Contributor
Author
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. https://github.com/scikit-learn/scikit-learn/pull/26243/changes This is the actual PR
Member
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. thanks — @betatim would you mind weighing in on how this implementation arose? EDIT: /feel free to review also :)
Contributor
Author
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. I think this mainly follows the numpy implementation ignoring cases of objects or ndarray specifics:
Member
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. What exactly are you looking for in terms of histroy Lucas? My guess is that like Omar said it is based on what is in Numpy, potentially minus some extra args/handling of edge cases.
Member
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.
If that's the case, then yeah, I'll start by looking at what NumPy does
Member
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. Yeah, the way these functions make their way into scikit-learn is "this exists in numpy, doesn't exist in array API, we need it, let's translate the numpy code" |
||
| a: Array, | ||
| /, | ||
| *, | ||
| axis: int | tuple[int, ...] | None, | ||
| xp: ModuleType, | ||
| ) -> Array: | ||
| """See docstring in `array_api_extra._delegation.py`.""" | ||
| mask = xp.isnan(a) | ||
| device_a = _compat.device(a) | ||
| x = xp.min( | ||
| xp.where(mask, xp.asarray(+xp.inf, dtype=a.dtype, device=device_a), a), | ||
| axis=axis, | ||
| ) | ||
| # Replace Infs from all NaN slices with NaN again | ||
| mask = xp.all(mask, axis=axis) | ||
| if xp.any(mask): | ||
| x = xp.where(mask, xp.asarray(xp.nan, dtype=x.dtype, device=device_a), x) | ||
| return x | ||
Uh oh!
There was an error while loading. Please reload this page.