Skip to content

Commit 06aa797

Browse files
committed
further import changes
1 parent afd68a3 commit 06aa797

File tree

10 files changed

+28
-37
lines changed

10 files changed

+28
-37
lines changed

httomolibgpu/cupywrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
cupy_run = False
21
try:
32
import cupy as cp
43
import nvtx
@@ -15,5 +14,6 @@
1514
)
1615
from unittest.mock import Mock
1716
import numpy as cp
17+
cupy_run = False
1818

1919
nvtx = Mock()

httomolibgpu/misc/corr.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929

3030
cp = cupywrapper.cp
3131
nvtx = cupywrapper.nvtx
32+
cupy_run = cupywrapper.cupy_run
3233

3334
from numpy import float32
3435
from unittest.mock import Mock
3536

36-
try:
37+
if cupy_run:
3738
from httomolibgpu.cuda_kernels import load_cuda_module
38-
except ImportError as e:
39+
else:
3940
load_cuda_module = Mock()
4041

4142

@@ -45,6 +46,7 @@
4546
]
4647

4748

49+
@nvtx.annotate()
4850
def median_filter(
4951
data: cp.ndarray,
5052
kernel_size: int = 3,
@@ -73,19 +75,6 @@ def median_filter(
7375
ValueError
7476
If the input array is not three dimensional.
7577
"""
76-
if cupywrapper.cupy_run:
77-
return __median_filter(data, kernel_size, dif)
78-
else:
79-
print("median_filter won't be executed because CuPy is not installed")
80-
return data
81-
82-
83-
@nvtx.annotate()
84-
def __median_filter(
85-
data: cp.ndarray,
86-
kernel_size: int = 3,
87-
dif: float = 0.0,
88-
) -> cp.ndarray:
8978
input_type = data.dtype
9079

9180
if input_type not in ["float32", "uint16"]:
@@ -154,8 +143,4 @@ def remove_outlier(
154143
if dif <= 0.0:
155144
raise ValueError("Threshold value (dif) must be positive and nonzero.")
156145

157-
if cupywrapper.cupy_run:
158-
return __median_filter(data, kernel_size, dif)
159-
else:
160-
print("remove_outlier won't be executed because CuPy is not installed")
161-
return data
146+
return median_filter(data, kernel_size, dif)

httomolibgpu/misc/morph.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525

2626
cp = cupywrapper.cp
2727
nvtx = cupywrapper.nvtx
28+
cupy_run = cupywrapper.cupy_run
2829

2930
from unittest.mock import Mock
3031

31-
try:
32+
if cupy_run:
3233
from cupyx.scipy.interpolate import interpn
33-
except ImportError as e:
34+
else:
3435
interpn = Mock()
3536

3637
from typing import Literal

httomolibgpu/misc/rescale.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
from httomolibgpu import cupywrapper
2424

2525
cp = cupywrapper.cp
26-
2726
nvtx = cupywrapper.nvtx
27+
2828
from typing import Literal, Optional, Tuple, Union
2929

3030
__all__ = [

httomolibgpu/prep/alignment.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525

2626
cp = cupywrapper.cp
2727
nvtx = cupywrapper.nvtx
28+
cupy_run = cupywrapper.cupy_run
2829

2930
from unittest.mock import Mock
3031

31-
try:
32+
if cupy_run:
3233
from cupyx.scipy.ndimage import map_coordinates
33-
except ImportError as e:
34+
else:
3435
map_coordinates = Mock()
3536

3637
from typing import Dict, List

httomolibgpu/prep/normalize.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525

2626
cp = cupywrapper.cp
2727
nvtx = cupywrapper.nvtx
28+
cupy_run = cupywrapper.cupy_run
2829

2930
from unittest.mock import Mock
3031

31-
try:
32+
if cupy_run:
3233
from cupy import mean
33-
except ImportError as e:
34+
else:
3435
mean = Mock()
3536

3637
from numpy import float32

httomolibgpu/prep/phase.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525

2626
cp = cupywrapper.cp
2727
nvtx = cupywrapper.nvtx
28+
cupy_run = cupywrapper.cupy_run
2829

2930
from unittest.mock import Mock
30-
try:
31+
if cupy_run:
3132
from httomolibgpu.cuda_kernels import load_cuda_module
3233
from cupyx.scipy.fft import fft2, ifft2, fftshift
33-
except ImportError as e:
34+
else:
3435
load_cuda_module = Mock()
3536
fft2 = Mock()
3637
ifft2 = Mock()

httomolibgpu/prep/stripe.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525

2626
cp = cupywrapper.cp
2727
nvtx = cupywrapper.nvtx
28+
cupy_run = cupywrapper.cupy_run
2829

2930
from unittest.mock import Mock
30-
try:
31+
if cupy_run:
3132
from cupyx.scipy.ndimage import median_filter, binary_dilation, uniform_filter1d
32-
except ImportError as e:
33+
else:
3334
median_filter = Mock()
3435
binary_dilation = Mock()
3536
uniform_filter1d = Mock()

httomolibgpu/recon/algorithm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525

2626
cp = cupywrapper.cp
2727
nvtx = cupywrapper.nvtx
28+
cupy_run = cupywrapper.cupy_run
2829

2930
from unittest.mock import Mock
30-
try:
31+
if cupy_run:
3132
from tomobar.methodsDIR_CuPy import RecToolsDIRCuPy
3233
from tomobar.methodsIR_CuPy import RecToolsIRCuPy
33-
except ImportError as e:
34+
else:
3435
RecToolsDIRCuPy = Mock()
3536
RecToolsIRCuPy = Mock()
3637

httomolibgpu/recon/rotation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525

2626
cp = cupywrapper.cp
2727
nvtx = cupywrapper.nvtx
28-
28+
cupy_run = cupywrapper.cupy_run
2929

3030
from unittest.mock import Mock
31-
try:
31+
if cupy_run:
3232
from httomolibgpu.cuda_kernels import load_cuda_module
3333
from cupyx.scipy.ndimage import shift, gaussian_filter
3434
from skimage.registration import phase_cross_correlation
3535
from cupyx.scipy.fftpack import get_fft_plan
3636
from cupyx.scipy.fft import rfft2
37-
except ImportError as e:
37+
else:
3838
load_cuda_module = Mock()
3939
shift = Mock()
4040
gaussian_filter = Mock()

0 commit comments

Comments
 (0)