Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork11.9k
API: Add .mT attribute for arrays#23762
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
The lower dimensional (1d and 2d) tests compare the behaviour of `.mT` against`.T` not swapaxes.
The test generates random shapes of a given length. This was previously usedwith min_dims=3. This excludes arrays of dimension 0, 1, 2 which we want.Instead we test all dimensions up to 7.
seberg left a comment
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.
Looks like a good start, will mark as draft for now if you don't mind, just unmark it when things are settling (not that I think there is much missing)!
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
This commit reduces the memory required by the test. Instead of explicitlyconstructing an array of shape `shape`, we now construct only the last dimand broadcast over that.
Hypothesis seems to be overkill for the provided situation. Use explicitlydefined values instead.
This commit causes `.mT` to raise a ValueError if ndim < 2. This is becausethe matrix transpose is undefined for 0 or 1 dimensional arrays and havingit implemented may lead to confusion by users.
rgommers commentedMay 17, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thanks for working on this Kai!
I'd say yes we want that (because of the analogue to |
charris commentedMay 17, 2023
This will need a release note. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Kai-Striega commentedMay 21, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@rgommers I'm happy to work on it in this PR, but I'm still learning about NumPy internals, meaning that the commit history could become quite messy as I learn (of course I'll try my best to keep it clean). As a summary, I think we should match the functions for
The next step for me is to add
I'm not really sure if this is the right direction, or if we even want to add |
mattip commentedMay 21, 2023
I would not touch the NumPy C-API with this PR. It is enough to add the attribute to ndarray and ma. If in the future we wish to export it via the C-API, that can be another PR. |
rgommers commentedMay 21, 2023
We don't need/want both a |
charris commentedMay 21, 2023
I rather like the idea of an |
This was decided to not be needed in the PR review.Skipping CI as I know it doesn't work and don't needCI to tell me that.[skip ci]
Kai-Striega commentedMay 22, 2023
I've removed the code adding it to the C-API (I think) and stopped working on adding an I may need some help structuring the code so that I can share it between |
seberg commentedMay 22, 2023
You have to add the new function to a header file now and include it, probably. If you check the test failures, you see they fail on compiler warnings. |
BvB93 left a comment
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.
Can you addndarray.mT annotations to the maininit.pyi stub file? The type is identical tondarray.T so you can just reuse that it:
Lines 986 to 987 incc0abd7
| @property | |
| defT(self:_ArraySelf)->_ArraySelf: ... |
Kai-Striega commentedJun 12, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@seberg I'vefinally got the masked array implementation working! I'm not sure if it's done correctly, could you take a look at my last commit? If it's right, I think I have three things left:
|
numpy/ma/core.py Outdated
| ifself._maskisnomask: | ||
| # TODO: Should this return a masked_array or regular array? | ||
| returnself._data.mT |
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.
A masked array. Otherwise, seems good. Although.transpose() has some_update_from_self stuff, it may make sense to just stick close to it in the off-chance it matters.
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'm struggling to replicate.transpose() as it uses the function version, not the attribute. I haven't been figured out how to do this (yet) and will leave it for another PR - maybe I can come back and tidy it up then if there are problems?
This function will be added in another PR.
Kai-Striega commentedJun 12, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
seberg left a comment
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.
LGTM, thanks, just should add the versionadded.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
seberg commentedJun 21, 2023
Thanks, lets put it in. After merging, I noticed that the docs actually render slightly incorrectly. Not a big deal, but maybe you want to follow up? I guess we need |
Kai-Striega commentedJun 22, 2023
Thanks that's my first C level contribution 👌. Let's hope for many more. I'll follow up with the docs rendering properly. |
Uh oh!
There was an error while loading.Please reload this page.
This is the initial commit for adding an
mT, or matrix transpose, attribute for arrays. It is still a work in progress and not done yet. Please note that this is my first time working on NumPy's C-API. The PR is mainly being submitted this early to confirm that I am on the right track.Things that are still needed:
[ ]np.transposearray_matrix_transpose_getand exit early if 1d arrayAnother note;
ndarray.Thas a corresponding functionnp.transpose, as part of this PR should we add a corresponding function for.mTe.g.np.matrix_transpose? If this is the case, should I add a function toPyArray_MatrixTransposetoshape.crather than defining the function insidegetset.cas is done with the regular transpose function?