-
Notifications
You must be signed in to change notification settings - Fork 3
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
ENH: add atleast_nd
#3
Conversation
3953b1d
to
60efb68
Compare
@asmeurer are you sure we want to allow not passing If we didn't allow that, I think we could make this package have no dependency on array-api-compat, which would make it a lot easier to vendor. From SciPy's perspective, we will always have access to |
246e2c8
to
ab8085d
Compare
ab8085d
to
9114494
Compare
Co-authored-by: Pamphile Roy <[email protected]>
2dae393
to
c417ab4
Compare
c417ab4
to
7ce7e2a
Compare
This is ready to merge from my side. |
We should probably try to get feedback from other people who would be using this. My feeling is that people might prefer to call atleast_nd(x) rather than atleast_nd(x, xp). I suppose one option would be to make xp optional, like
That way you can get the best of both worlds. We would probably want to move that logic into a common decorator. And also do some indirection for array_api_compat so that people can easily swap it out for a vendored version. (although OTOH the more indirection and decorators we use, the harder it is for people to just copy-paste a single function). |
@betatim @ogrisel @thomasjpfan hello 👋 this is the start of an attempt to share array-agnostic implementations of functions that build on top of the standard across consumer libraries. So instead of storing private implementations in each consumer library, they'll be stored here and one can do: from ... import array_api_extra as xpx
...
xpx.atleast_nd(x, ndim=2, xp=xp) I'd appreciate if any of you could weigh in from a scikit-learn perspective on the question of whether these functions should require We could make If we force developers to pass |
I should point out that not using array-api-compat will make writing this library much harder as you would have to avoid using APIs that differ between the array libraries (or else effectively re-implement array-api-compat in helpers). I personally don't think it's a worthwhile goal. |
Which APIs are you thinking of? I forgot that we're probably at least going to need array-api-compat's To be clear, |
Literally any API you might use. For example, in this function you're using
I suppose that does sidestep the issue. I still think it would be annoying as a user to have to pass in xp to every function. I'm a little surprised you're doing that in scipy, but I can't imagine every library wants to do that. |
To clarify, the user-base for this library is consumer-library authors who are already using array-api-compat namespaces everywhere. In other words, we are just targeting the spec, not existing libraries. |
I prefer always passing it in as an argument. |
ca64ab2
to
046ea33
Compare
046ea33
to
97a792a
Compare
hello @KelSolaar too! You had previously expressed interest in functions like |
5e8c6f7
to
f17e601
Compare
Here's a PR showing that vendoring this package and using |
@vnmabus perhaps you have an opinion on the question in #3 (comment) too? |
I am not sure of why you request my particular feedback. Personally, I think that it is probably better to prevent writing code that do unnecessary calls to I wonder if it wouldn't be cleaner to have a function that receives the |
Mainly because I don't know many other array-api-compat users!
Cool idea! I guess something like the following would do it? extra_funcs = {'atleast_nd': atleast_nd}
def get_extra_namespace(xp: ModuleType) -> ModuleType:
class ExtraNamespace:
def __getattr__(self, name: str):
if name in extra_funcs:
func = functools.partial(extra_funcs[name], xp=xp)
return func
else:
return getattr(xp, name)
# or `return AttributeError` ?
return ExtraNamespace(xp) I'm not sure whether we'd want to use that yet in SciPy, since in most functions we would only be calling an xp = array_namespace(x)
xpx = get_extra_namespace(xp)
...
x = xpx.atleast_nd(x, ndim=5)
y = xp.sum(x) It would probably be better to keep uses of the two patterns separate, to avoid Maybe it would be better for Thanks for the thoughts! |
In scikit-learn we use the I don't have a strong opinion either way. It feels weird to pass it in, but it saves some repetitive code, but then making it optional you need repetitive code again (or decorator). I am not massively convinced regarding the performance benefit of not repeatedly calling |
I opened gh-6 to discuss potential alternatives to the I'm going to merge this as the function is passing NumPy-quality tests, works in SciPy, and is well documented. Thanks all for the thoughts! |
OK, that's fine. I think we can easily change things around in the future without too many backwards compatibility concerns. |
Did you want to make a release on PyPI? If we set up something like https://github.com/data-apis/array-api-compat/blob/main/.github/workflows/publish-package.yml and set up things on PyPI. |
Sure, if you could do whatever needs Owner permissions I can do the rest - I would like to learn the process. |
If you want you can try to set it up yourself, and add me as an owner on PyPI. I'll give you maintain role on this repo, which should hopefully be enough to add the right info to the repo settings. I would start with the publish file from array-api-compat, as well as the instructions at data-apis/array-api-compat#51 (I don't know if there are better docs for this somewhere). The best thing to do is to get everything working on TestPyPI first, and then once you have that working, enable publishing to real PyPI. I use a workflow where I push a tag up to the repo, but if you'd prefer to do a release via the web interface I think you might need to change things a little bit. Just remember that once you push a release to PyPI, you cannot undo it. If there's a problem, the only way to fix it is to bump the version number. I would also recommend adding https://github.com/data-apis/array-api-compat/blob/main/.github/dependabot.yml and https://github.com/data-apis/array-api-compat/blob/main/.github/workflows/dependabot-auto-merge.yml to this repo. That will keep the GitHub Actions versions up-to-date automatically. Actually the newest version of publish-package is supposed to have something that makes setting up PyPI easier https://github.com/pypa/gh-action-pypi-publish/releases |
Thanks Aaron, sounds good to me.
I suppose there is Henry’s https://learn.scientific-python.org/development/guides/gha-pure/#job-setup, but who knows which is “better” :) The repo template (scientific-python/cookie) already included dependabot. I’ll add the auto-merge workflow. |
@asmeurer I've requested access for the all contributors bot, would you be able to grant that? And could you also import the project on readthedocs? |
I think this might be something we used to have but removed, so I'll need to check if that's the case and why it was removed if so.
Let's use GitHub pages (or netlify if you prefer) so the docs appear under data-apis.org like the rest of the projects. |
No description provided.