-
Notifications
You must be signed in to change notification settings - Fork 12
ENH: add quantile
#341
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 quantile
#341
Conversation
This makes quantile available when the version of Scipy is not new enough to support array API inputs.
quantile
available for old scipy versionquantile
welcome :)
I would rather merge any changes to the implementation into SciPy first, before diverging into uncharted territory with LLM magic here.
Sounds fine, existing |
[1., 3.]], dtype=array_api_strict.float64) | ||
""" | ||
xp = array_namespace(x, q) if xp is None else xp | ||
|
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.
scikit-learn/scikit-learn#31671 (comment) suggests that delegation to some existing array libraries may be desirable here
We can add it back later if we need it
_funcs.py was getting too long.
I appeased the linter for you |
# Promote to common dtype | ||
x = xp.astype(x, xp.float64) | ||
q_arr = xp.astype(q_arr, xp.float64) | ||
q_arr = xp.asarray(q_arr, device=_compat.device(x)) |
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.
the "common dtype" is always float64
?
elif not isinstance(axis, int): # pyright: ignore[reportUnnecessaryIsInstance] | ||
raise ValueError("`axis` must be an integer or None.") # noqa: EM101 | ||
elif axis >= ndim or axis < -ndim: | ||
raise ValueError("`axis` is not compatible with the shapes of the inputs.") # noqa: EM101 |
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.
nit: could specify out of ndim
bounds
I am breaking out some of the lint changes into gh-344 |
diff all tidied up |
With the changes to the liniting/pre-commit setup: is https://github.com/evilmartians/lefthook the lefthook you are now using? I think the docs/ And/or: it would be nice to have instructions for how to run the required tools to make the CI checks happy that doesn't involve tools calling tools calling tools. I'm not sure I care enough about |
Please point out what seems to need tidying up! Bear in mind that the concept of a git pre-commit hook and the tool
If you want an easy workflow, everything you need should be described at https://data-apis.org/array-api-extra/contributing.html#development-workflow. It is effectively:
It can't get much simpler than that (this is a huge improvement on many projects I have contributed to). I am keen to make this workflow the best it can be, so let me know if you have any ideas for improvements. If you do not want to install Pixi, or otherwise want to use a different workflow, that is fine, and I am keen to accept contributions which accommodate for alternative workflows, while not being a detriment to other workflows. I will not be volunteering my time to work on speculative accommodations for alternative workflows, though, as I strongly believe that the Pixi workflow is both essential to and sufficient for the project. |
Yes |
I feel your pain, which is why I am so excited about Pixi, as a potential replacement for all of them. |
I added a delegation to dask to solve some of the errors related to import array_api_compat.dask.array as xp
x = xp.asarray([1, 2, 3, 4, 5])
xp.quantile(x, 0.5) this leads to the following error:
What is the normal procedure for dealing with something like this? Can we skip the test for dask? |
Yep, the normal procedure would be:
|
Can I install pixi in an existing conda env and it won't touch or modify things outside of that conda env? I don't want to blindly install something that (potentially) messes with my shell or might end up breaking things for other projects. And figuring out the answer to that question isn't easy, I think. Especially because most of the instructions are "just install pixi" - which if I was starting from scratch would be fine, but I want the "install pixi the hard way" instructions so I know what it might (or might not) break |
I don't think that is possible, but I will ask and let you know if it is. |
The best I can do is say that I have had no such problems 🤷♂️ |
Closes #340
This makes quantile available when the version of Scipy is not new enough to support array API inputs.
This is my first venture into
array-api-extra
land. The idea in #340 was to use the scipy implementation if available and otherwise use a copy of that implementation. This is what this PR implements.Given that this was mostly a "copy&paste" job I thought it would be a good task to learn more about using "agents", so I asked Cursor to do the work, etc. From what I can tell reviewing the diff it looks sensible. But the caveat is that I've never thought about how to write
quantile
myself. So you might consider this "the blind leading the blind". There are a few differences to the scipy implementation, mostly more "make this an array" and dealing with squashing/maintaining dimension handling. I can't explain to you why these differences make sense :-/ - both implementations seem sensible when looked at individually. Maybe someone here can explain how that fits with the fact that the diff isn't zero :DA few of the pre-commit checks related to numpydoc conventions don't understand the idea of only having a full docstring in
_delegation.py
and not also in_funcs.py
- I turned off the checks when there were no other errors left. I'm not sure I get the point of some of the ruff checks that failed, hence thenoqa
comments on theraise
statements (can change them to assign the message to a variable first)