-
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 kron
and expand_dims
#7
Conversation
@mdhaber I've taken your implementations from scipy/scipy#20077 (comment), made some modifications for edge-cases, and added type annotations as well as xp-compatible tests and docs based on NumPy's. Any feedback appreciated if you'd like to take a look! |
Indeed it can! |
I was just zombie-translating from NumPy to array API with that, so I'm afraid I don't have any insight here. |
Is this I still think this should be in array API properly, but happy for it to live here until / if that happens. |
Fantastic!!! I specifically asked for this change to the array API (going from supporting a single axis to a tuple of axes), but it hasn't happened yet. See: data-apis/array-api#760 I use such a thing literally all the time. Edit: Also, some of the existing libraries (NumPy and CuPy, but not PyTorch) do support expand_dims with a tuple of axes already. Maybe you want to dispatch directly to them in those cases? |
aha, reading @asmeurer's comments in that issue I see the concern for ambiguity now. This implementation chooses to always add the same number of dimensions as the length of the tuple, and resolves negatives by taking the positions modulo the number of dimensions in the output. I should check that this matches what NumPy does, and add a note to the docs.
My intention with this package is to target just the standard - it isn't concerned with which real-world implementations exist (other than array-api-strict for testing). It's quite simple to write small wrappers which delegate to known array libraries around array-agnostic functions like this, but I would rather keep that separate for now. Perhaps a separate package could do that and this will just be a backend for that, or perhaps that will take over this package eventually. I would rather that consumer libraries deal with which array libraries they would like to delegate to in their own code for now. |
Yeah, I get the idea for keeping it simple! Makes sense, just wanted to point it out if you weren't aware. I'm just happy to not have to maintain an |
Co-authored-by: Matt Haberland <[email protected]>
This PR is ready from my side. I'll leave it open for a while for any comments. I've documented the resolution to the ambiguity in data-apis/array-api#760, which is to follow NumPy in disallowing a tuple containing both positive and negative indices referring to the same position in the expanded shape. |
|
Gentle bump here! If I don't hear back, I'll probably merge this soon and circle back before a new release is cut. |
x-ref data-apis/array-api#837