fepegar / torchio
Showing 1 of 1 files from the diff.

@@ -1,4 +1,4 @@
Loading
1 -
import numpy
1 +
import numpy as np
2 2
import torch
3 3
4 4
@@ -6,12 +6,26 @@
Loading
6 6
7 7
    @staticmethod
8 8
    def fourier_transform(tensor: torch.Tensor) -> torch.Tensor:
9 -
        transformed = numpy.fft.fftn(tensor)
10 -
        fshift = numpy.fft.fftshift(transformed)
11 -
        return torch.from_numpy(fshift)
9 +
        try:
10 +
            import torch.fft
11 +
            transformed = torch.fft.fftn(tensor)
12 +
            fshift = torch.fft.fftshift(transformed)
13 +
            return fshift
14 +
        except ModuleNotFoundError or AttributeError:
15 +
            import torch
16 +
            transformed = np.fft.fftn(tensor)
17 +
            fshift = np.fft.fftshift(transformed)
18 +
            return torch.from_numpy(fshift)
12 19
13 20
    @staticmethod
14 21
    def inv_fourier_transform(tensor: torch.Tensor) -> torch.Tensor:
15 -
        f_ishift = numpy.fft.ifftshift(tensor)
16 -
        img_back = numpy.fft.ifftn(f_ishift)
17 -
        return torch.from_numpy(img_back)
22 +
        try:
23 +
            import torch.fft
24 +
            f_ishift = torch.fft.ifftshift(tensor)
25 +
            img_back = torch.fft.ifftn(f_ishift)
26 +
            return img_back
27 +
        except ModuleNotFoundError or AttributeError:
28 +
            import torch
29 +
            f_ishift = np.fft.ifftshift(tensor)
30 +
            img_back = np.fft.ifftn(f_ishift)
31 +
            return torch.from_numpy(img_back)
Files Coverage
src/torchio 86.19%
Project Totals (92 files) 86.19%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading