-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
#6213 Prepend "meta"
to MetaTensor.__repr__
and MetaTensor.__str__
for easier identification
#6214
Conversation
…easier identification Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
I think pytorch has recently improved this for tensor subclasses: >>> import torch
>>> class SubTensor(torch.Tensor):
... pass
...
>>> a = SubTensor([1.0])
>>> print(a)
SubTensor([1.]) |
@wyli Running I've tried seeing what would happen if I would comment out Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb 7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)] on win32
>>> import monai
>>> mt = monai.data.MetaTensor([1.])
>>> print(mt)
Metadata
affine: tensor([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]], dtype=torch.float64)
space: RAS
Applied operations
[] |
Hi @MathijsdeBoer my example in the previous comment is not about monai, it's a pytorch demo to show subclassing... |
@wyli Right, but isn't |
these are from the MetaObj... Lines 157 to 168 in d57bff6
that's why I think this PR is a good idea.. |
comment out |
Right, order matters. I don't often work with multiple inheritance in my projects, so I didn't think of that! Thanks! |
/build |
…aTensor.__str__` for easier identification (Project-MONAI#6214) Discussed in Project-MONAI#6213 ### Description Prepends `"meta"` to the `MetaTensor.__repr__` and `MetaTensor.__str__` output so printing a MetaTensor does not look the exact same as a regular `torch.Tensor`. I don't expect this change to cause any breaks, with me running the risk of invoking [xkcd 1172](https://xkcd.com/1172/). --- 1 failure in `./runtests.sh -f -u --net --coverage`: ```text ====================================================================== FAIL: test_values (tests.test_tciadataset.TestTciaDataset) ---------------------------------------------------------------------- Traceback (most recent call last): File "D:\PythonProjects\MONAI-SaveImageFormatting\tests\test_tciadataset.py", line 72, in test_values self.assertTrue( AssertionError: False is not true ``` ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [x] New tests added to cover the changes. - [x] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [x] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [x] In-line docstrings updated. --------- Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
…aTensor.__str__` for easier identification (Project-MONAI#6214) Discussed in Project-MONAI#6213 ### Description Prepends `"meta"` to the `MetaTensor.__repr__` and `MetaTensor.__str__` output so printing a MetaTensor does not look the exact same as a regular `torch.Tensor`. I don't expect this change to cause any breaks, with me running the risk of invoking [xkcd 1172](https://xkcd.com/1172/). --- 1 failure in `./runtests.sh -f -u --net --coverage`: ```text ====================================================================== FAIL: test_values (tests.test_tciadataset.TestTciaDataset) ---------------------------------------------------------------------- Traceback (most recent call last): File "D:\PythonProjects\MONAI-SaveImageFormatting\tests\test_tciadataset.py", line 72, in test_values self.assertTrue( AssertionError: False is not true ``` ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [x] New tests added to cover the changes. - [x] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [x] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [x] In-line docstrings updated. --------- Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
Discussed in #6213
Description
Prepends
"meta"
to theMetaTensor.__repr__
andMetaTensor.__str__
output so printing a MetaTensor does not look the exact same as a regulartorch.Tensor
.I don't expect this change to cause any breaks, with me running the risk of invoking xkcd 1172.
1 failure in
./runtests.sh -f -u --net --coverage
:Types of changes
./runtests.sh -f -u --net --coverage
../runtests.sh --quick --unittests --disttests
.