|
12 | 12 | raven_filter, |
13 | 13 | ) |
14 | 14 | from numpy.testing import assert_allclose |
15 | | -from .stripe_cpu_reference import raven_filter_cpu |
| 15 | +from .stripe_cpu_reference import raven_filter_numpy |
16 | 16 |
|
17 | 17 | def test_remove_stripe_ti_on_data(data, flats, darks): |
18 | 18 | # --- testing the CuPy implementation from TomoCupy ---# |
@@ -72,16 +72,39 @@ def test_stripe_raven_cupy(data, flats, darks): |
72 | 72 |
|
73 | 73 | data = normalize(data, flats, darks, cutoff=10, minus_log=True) |
74 | 74 |
|
75 | | - data_after_raven_gpu = raven_filter(cp.copy(data)) |
76 | | - data_after_raven_cpu = cp.asarray(raven_filter_cpu(cp.copy(data).get())) |
| 75 | + data_after_raven_gpu = raven_filter(cp.copy(data)).get() |
| 76 | + data_after_raven_cpu = raven_filter_numpy(cp.copy(data).get()) |
77 | 77 |
|
78 | | - cp.testing.assert_allclose(data_after_raven_cpu, data_after_raven_gpu, rtol=0, atol=4e-01) |
| 78 | + assert_allclose(data_after_raven_cpu, data_after_raven_gpu, rtol=0, atol=4e-01) |
79 | 79 |
|
80 | 80 | data = None #: free up GPU memory |
81 | 81 | # make sure the output is float32 |
82 | 82 | assert data_after_raven_gpu.dtype == np.float32 |
83 | 83 | assert data_after_raven_gpu.shape == data_after_raven_cpu.shape |
84 | 84 |
|
| 85 | +@pytest.mark.parametrize("uvalue", [20, 50, 100]) |
| 86 | +@pytest.mark.parametrize("nvalue", [2, 4, 6]) |
| 87 | +@pytest.mark.parametrize("vvalue", [2, 4]) |
| 88 | +@pytest.mark.parametrize("pad_x", [0, 10, 20]) |
| 89 | +@pytest.mark.parametrize("pad_y", [0, 10, 20]) |
| 90 | +@cp.testing.numpy_cupy_allclose(rtol=0, atol=3e-01) |
| 91 | +def test_stripe_raven_parameters_cupy(ensure_clean_memory, xp, uvalue, nvalue, vvalue, pad_x, pad_y): |
| 92 | + # because it's random, we explicitly seed and use numpy only, to match the data |
| 93 | + np.random.seed(12345) |
| 94 | + data = np.random.random_sample(size=(256, 5, 512)).astype(np.float32) * 2.0 + 0.001 |
| 95 | + data = xp.asarray(data) |
| 96 | + |
| 97 | + if xp.__name__ == "numpy": |
| 98 | + results = raven_filter_numpy( |
| 99 | + data, uvalue=uvalue, nvalue=nvalue, vvalue=vvalue, pad_x=pad_x, pad_y=pad_y |
| 100 | + ).astype(np.float32) |
| 101 | + else: |
| 102 | + results = raven_filter( |
| 103 | + data, uvalue=uvalue, nvalue=nvalue, vvalue=vvalue, pad_x=pad_x, pad_y=pad_y |
| 104 | + ).get() |
| 105 | + |
| 106 | + return xp.asarray(results) |
| 107 | + |
85 | 108 | @pytest.mark.perf |
86 | 109 | def test_stripe_removal_sorting_cupy_performance(ensure_clean_memory): |
87 | 110 | data_host = ( |
@@ -155,25 +178,6 @@ def test_raven_filter_performance(ensure_clean_memory): |
155 | 178 |
|
156 | 179 | assert "performance in ms" == duration_ms |
157 | 180 |
|
158 | | -# @pytest.mark.perf |
159 | | -# def test_raven_filter_cpu_performance(ensure_clean_memory): |
160 | | -# data_host = ( |
161 | | -# np.random.random_sample(size=(1801, 5, 2560)).astype(np.float32) * 2.0 + 0.001 |
162 | | -# ) |
163 | | -# data = cp.asarray(data_host, dtype=np.float32) |
164 | | -# |
165 | | -# # do a cold run first |
166 | | -# raven_filter_cpu(cp.copy(data).get()) |
167 | | -# |
168 | | -# start = time.perf_counter_ns() |
169 | | -# for _ in range(10): |
170 | | -# raven_filter_cpu(cp.copy(data).get()) |
171 | | -# |
172 | | -# duration_ms = float(time.perf_counter_ns() - start) * 1e-6 / 10 |
173 | | -# |
174 | | -# assert "performance in ms" == duration_ms |
175 | | - |
176 | | - |
177 | 181 | def test_remove_all_stripe_on_data(data, flats, darks): |
178 | 182 | # --- testing the CuPy implementation from TomoCupy ---# |
179 | 183 | data = normalize(data, flats, darks, cutoff=10, minus_log=True) |
|
0 commit comments