-
Notifications
You must be signed in to change notification settings - Fork 16
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
Fix #470 non adapted sample indices in gradients during sorting #480
Conversation
Here is a pre-built version of the code in this pull request: wheels.zip, you can install it locally by unzipping |
python/metatensor-operations/metatensor/operations/_dispatch.py
Outdated
Show resolved
Hide resolved
7dbd0ed
to
a553a3d
Compare
descending: bool, | ||
) -> TensorBlock: | ||
""" | ||
Sorts a single TensorBlock without the user input checking and sorting of gradients |
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.
Sorts a single TensorBlock without the user input checking and sorting of gradients | |
Sorts a single gradient TensorBlock. This is different from `_sort_single_block` because we need to update the sample differently (since gradient samples are pointers into the values samples) |
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.
updated this doc and embedded suggested change into it
properties=Labels(["p"], np.array([[1], [0]])), | ||
) | ||
|
||
# fmt: off |
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.
this should not be needed
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.
not needed but black makes this really hard to read so I turned it off
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 partially agree with you that black is not ideal here, but I would prefer not to start adding fmt: off
or # noqa
too often in the code. I would rather live with slightly worst formatting but have it consistent everywhere.
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.
This have strong feelings on. This sort test is already hard to understand as it is, and the black formatting made it much harder.
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.
Unlike other tests, the order must be much easier to read so one can follow what is how moved. I added comments why it is turned off.
Added commit with changes from review suggestions |
1cca318
to
f495f7e
Compare
e716901
to
55c994e
Compare
- Splitting sorted tensors into an ascending and descending so the fix can be more robustly tested - Adding dispatched arange_like to create inverse mapping for reasigning samples in gradients
55c994e
to
08e19e7
Compare
Fixes #470
Waiting till #479 is merged to also add finite difference test
Contributor (creator of pull-request) checklist
Reviewer checklist
📚 Documentation preview 📚: https://metatensor--480.org.readthedocs.build/en/480/