Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Li <wenqil@nvidia.com>
  • Loading branch information
wyli committed May 16, 2023
1 parent e084885 commit ee333ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions monai/data/meta_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,12 @@ def __str__(self):
"""
return f"meta{str(self.as_tensor())}"

def __format__(self, format_spec):
"""
returns the output of pytorch tensor's ``__format__`` method.
"""
return self.as_tensor().__format__(format_spec)

def print_verbose(self) -> None:
"""Verbose print with meta data."""
print(self)
Expand Down
1 change: 1 addition & 0 deletions tests/test_meta_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ def test_str(self):
t = MetaTensor([1.0], affine=torch.tensor(1), meta={"fname": "filename"})
self.assertEqual(str(t), "metatensor([1.])")
self.assertEqual(t.__repr__(), "metatensor([1.])")
self.assertEqual("{:.2f}".format(t[0]), "1.00")

def test_shape(self):
s = MetaTensor([1])
Expand Down

0 comments on commit ee333ea

Please sign in to comment.