Skip to content

Commit 775935d

Browse files
monai-botwyli
andauthored
auto updates (#5438)
Signed-off-by: monai-bot <monai.miccai2019@gmail.com> fixes #5444 Signed-off-by: monai-bot <monai.miccai2019@gmail.com> Signed-off-by: Wenqi Li <wenqil@nvidia.com> Co-authored-by: Wenqi Li <wenqil@nvidia.com> Co-authored-by: Wenqi Li <831580+wyli@users.noreply.github.com>
1 parent e44f3b9 commit 775935d

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

monai/data/meta_tensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def as_tensor(self) -> torch.Tensor:
321321
Return the `MetaTensor` as a `torch.Tensor`.
322322
It is OS dependent as to whether this will be a deep copy or not.
323323
"""
324-
return self.as_subclass(torch.Tensor) # type: ignore
324+
return self.as_subclass(torch.Tensor)
325325

326326
def get_array(self, output_type=np.ndarray, dtype=None, device=None, *_args, **_kwargs):
327327
"""

monai/metrics/cumulative_average.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
# limitations under the License.
1111

1212
import warnings
13-
from typing import Any, Optional, Union
13+
from typing import Any, Optional
1414

1515
import torch
1616
import torch.distributed as dist
17-
from numpy.typing import NDArray
17+
18+
from monai.config import NdarrayOrTensor
1819

1920

2021
class CumulativeAverage:
@@ -52,7 +53,7 @@ def reset(self) -> None:
5253
self.count = torch.tensor(0, dtype=torch.float)
5354
self.is_distributed = dist.is_available() and dist.is_initialized()
5455

55-
def get_current(self, to_numpy: bool = True) -> Union[NDArray, torch.Tensor]:
56+
def get_current(self, to_numpy: bool = True) -> NdarrayOrTensor:
5657
"""
5758
returns the most recent value (averaged across processes)
5859
@@ -74,7 +75,7 @@ def get_current(self, to_numpy: bool = True) -> Union[NDArray, torch.Tensor]:
7475

7576
return val
7677

77-
def aggregate(self, to_numpy: bool = True) -> Union[NDArray, torch.Tensor]:
78+
def aggregate(self, to_numpy: bool = True) -> NdarrayOrTensor:
7879
"""
7980
returns the total average value (averaged across processes)
8081

tests/test_nifti_rw.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ def test_write_3d(self):
181181
writer_obj.set_metadata({"affine": np.diag([1, 1, 1, 1]), "original_affine": np.diag([1.4, 1, 1, 1])})
182182
writer_obj.write(image_name, verbose=True)
183183
out = nib.load(image_name)
184-
np.testing.assert_allclose(out.get_fdata(), [[[0, 1, 2], [3, 4, 5]]])
185-
np.testing.assert_allclose(out.affine, np.diag([1.4, 1, 1, 1]))
184+
np.testing.assert_allclose(out.get_fdata(), [[[0, 1, 2], [3, 4, 5]]], atol=1e-4, rtol=1e-4)
185+
np.testing.assert_allclose(out.affine, np.diag([1.4, 1, 1, 1]), atol=1e-4, rtol=1e-4)
186186

187187
image_name = os.path.join(out_dir, "test1.nii.gz")
188188
img = p(np.arange(5).reshape((1, 1, 5)))
@@ -205,8 +205,8 @@ def test_write_4d(self):
205205
writer_obj.set_metadata({"affine": np.diag([1.4, 1, 1, 1]), "original_affine": np.diag([1, 1.4, 1, 1])})
206206
writer_obj.write(image_name, verbose=True)
207207
out = nib.load(image_name)
208-
np.testing.assert_allclose(out.get_fdata(), [[[[0, 1], [2, 3], [4, 5]]]])
209-
np.testing.assert_allclose(out.affine, np.diag([1, 1.4, 1, 1]))
208+
np.testing.assert_allclose(out.get_fdata(), [[[[0, 1], [2, 3], [4, 5]]]], atol=1e-4, rtol=1e-4)
209+
np.testing.assert_allclose(out.affine, np.diag([1, 1.4, 1, 1]), atol=1e-4, rtol=1e-4)
210210

211211
image_name = os.path.join(out_dir, "test1.nii.gz")
212212
img = p(np.arange(5).reshape((1, 1, 5, 1)))
@@ -232,8 +232,10 @@ def test_write_5d(self):
232232
np.testing.assert_allclose(
233233
out.get_fdata(),
234234
np.array([[[[[0.0, 1.0], [2.0, 3.0]], [[4.0, 5.0], [6.0, 7.0]], [[8.0, 9.0], [10.0, 11.0]]]]]),
235+
atol=1e-4,
236+
rtol=1e-4,
235237
)
236-
np.testing.assert_allclose(out.affine, np.diag([1.4, 1, 1, 1]))
238+
np.testing.assert_allclose(out.affine, np.diag([1.4, 1, 1, 1]), atol=1e-4, rtol=1e-4)
237239

238240
image_name = os.path.join(out_dir, "test1.nii.gz")
239241
img = p(np.arange(10).reshape((1, 1, 5, 1, 2)))

tests/test_to_tensord.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
cp, _ = optional_import("cupy")
2222

23-
2423
im = [[1, 2], [3, 4]]
2524

2625
TESTS = [(im, (2, 2))]

0 commit comments

Comments
 (0)