Passed
Push — master ( 1c5439...729305 )
by Fernando
01:12
created

TestPad.test_nans_history()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
import torch
2
import SimpleITK as sitk
3
import torchio as tio
4
from torchio.utils import sitk_to_nib
5
from ...utils import TorchioTestCase
6
7
8
class TestPad(TorchioTestCase):
9
    """Tests for `Pad`."""
10
    def test_pad(self):
11
        image = self.sample_subject.t1
12
        padding = 1, 2, 3, 4, 5, 6
13
        sitk_image = image.as_sitk()
14
        low, high = padding[::2], padding[1::2]
15
        sitk_padded = sitk.ConstantPad(sitk_image, low, high, 0)
16
        tio_padded = tio.Pad(padding, padding_mode=0)(image)
17
        sitk_tensor, sitk_affine = sitk_to_nib(sitk_padded)
18
        tio_tensor, tio_affine = sitk_to_nib(tio_padded.as_sitk())
19
        self.assertTensorEqual(sitk_tensor, tio_tensor)
20
        self.assertTensorEqual(sitk_affine, tio_affine)
21
22
    def test_nans_history(self):
23
        padded = tio.Pad(1, padding_mode=2)(self.sample_subject)
24
        again = padded.history[0](self.sample_subject)
25
        assert not torch.isnan(again.t1.data).any()
26