-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconftest.py
More file actions
215 lines (161 loc) · 5.59 KB
/
Copy pathconftest.py
File metadata and controls
215 lines (161 loc) · 5.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import os
import cupy as cp
import numpy as np
import pytest
import gc
def pytest_addoption(parser):
parser.addoption(
"--performance",
action="store_true",
default=False,
help="run performance tests only",
)
def pytest_configure(config):
config.addinivalue_line("markers", "perf: mark test as performance test")
def pytest_collection_modifyitems(config, items):
if config.getoption("--performance"):
skip_other = pytest.mark.skip(reason="not a performance test")
for item in items:
if "perf" not in item.keywords:
item.add_marker(skip_other)
else:
skip_perf = pytest.mark.skip(
reason="performance test - use '--performance' to run"
)
for item in items:
if "perf" in item.keywords:
item.add_marker(skip_perf)
CUR_DIR = os.path.abspath(os.path.dirname(__file__))
@pytest.fixture(scope="session")
def test_data_path():
return os.path.join(CUR_DIR, "large_data_archive")
@pytest.fixture(scope="session")
def i12_dataset1_file(test_data_path):
in_file = os.path.join(test_data_path, "i12_dataset1.npz")
return np.load(in_file)
@pytest.fixture
def i12_dataset1(i12_dataset1_file):
return (
cp.asarray(i12_dataset1_file["projdata"]),
i12_dataset1_file["angles"],
cp.asarray(i12_dataset1_file["flats"]),
cp.asarray(i12_dataset1_file["darks"]),
)
@pytest.fixture(scope="session")
def i12_dataset2_file(test_data_path):
in_file = os.path.join(test_data_path, "i12_dataset2.npz")
return np.load(in_file)
@pytest.fixture
def i12_dataset2(i12_dataset2_file):
return (
cp.asarray(i12_dataset2_file["projdata"]),
i12_dataset2_file["angles"],
cp.asarray(i12_dataset2_file["flats"]),
cp.asarray(i12_dataset2_file["darks"]),
)
@pytest.fixture(scope="session")
def i12_dataset3_file(test_data_path):
in_file = os.path.join(test_data_path, "i12_dataset3.npz")
return np.load(in_file)
@pytest.fixture
def i12_dataset3(i12_dataset3_file):
return (
cp.asarray(i12_dataset3_file["proj1"]),
cp.asarray(i12_dataset3_file["proj2"]),
cp.asarray(i12_dataset3_file["flats"]),
cp.asarray(i12_dataset3_file["darks"]),
)
@pytest.fixture(scope="session")
def i12_dataset4_file(test_data_path):
in_file = os.path.join(test_data_path, "i12_dataset4.npz")
return np.load(in_file)
@pytest.fixture
def i12_dataset4(i12_dataset4_file):
return (
cp.asarray(i12_dataset4_file["projdata"]),
i12_dataset4_file["angles"],
cp.asarray(i12_dataset4_file["flats"]),
cp.asarray(i12_dataset4_file["darks"]),
)
@pytest.fixture(scope="session")
def i13_dataset1_file(test_data_path):
in_file = os.path.join(test_data_path, "i13_dataset1.npz")
return np.load(in_file)
@pytest.fixture
def i13_dataset1(i13_dataset1_file):
return (
cp.asarray(i13_dataset1_file["projdata"]),
i13_dataset1_file["angles"],
cp.asarray(i13_dataset1_file["flats"]),
cp.asarray(i13_dataset1_file["darks"]),
)
@pytest.fixture(scope="session")
def i13_dataset2_file(test_data_path):
in_file = os.path.join(test_data_path, "i13_dataset2.npz")
return np.load(in_file)
@pytest.fixture
def i13_dataset2(i13_dataset2_file):
return (
cp.asarray(i13_dataset2_file["projdata"]),
i13_dataset2_file["angles"],
cp.asarray(i13_dataset2_file["flats"]),
cp.asarray(i13_dataset2_file["darks"]),
)
@pytest.fixture(scope="session")
def i13_dataset3_file(test_data_path):
in_file = os.path.join(test_data_path, "i13_dataset3.npz")
return np.load(in_file)
@pytest.fixture
def i13_dataset3(i13_dataset3_file):
return (
cp.asarray(i13_dataset3_file["projdata"]),
i13_dataset3_file["angles"],
cp.asarray(i13_dataset3_file["flats"]),
cp.asarray(i13_dataset3_file["darks"]),
)
@pytest.fixture(scope="session")
def k11_dataset1_file(test_data_path):
in_file = os.path.join(test_data_path, "k11_dataset1.npz")
return np.load(in_file)
@pytest.fixture
def k11_dataset1(k11_dataset1_file):
return (
cp.asarray(k11_dataset1_file["projdata"]),
k11_dataset1_file["angles"],
cp.asarray(k11_dataset1_file["flats"]),
cp.asarray(k11_dataset1_file["darks"]),
)
@pytest.fixture(scope="session")
def geant4_dataset1_file(test_data_path):
in_file = os.path.join(test_data_path, "geant4_dataset1.npz")
return np.load(in_file)
@pytest.fixture
def geant4_dataset1(geant4_dataset1_file):
return (
cp.asarray(geant4_dataset1_file["projdata"]),
geant4_dataset1_file["angles"],
cp.asarray(geant4_dataset1_file["flats"]),
cp.asarray(geant4_dataset1_file["darks"]),
)
@pytest.fixture(scope="session")
def synth_tomophantom1_file(test_data_path):
in_file = os.path.join(test_data_path, "synth_tomophantom1.npz")
return np.load(in_file)
@pytest.fixture
def synth_tomophantom1_dataset(synth_tomophantom1_file):
return (
cp.asarray(cp.swapaxes(synth_tomophantom1_file["projdata"], 0, 1)),
synth_tomophantom1_file["angles"],
)
@pytest.fixture
def ensure_clean_memory():
gc.collect()
cp.get_default_memory_pool().free_all_blocks()
cp.get_default_pinned_memory_pool().free_all_blocks()
yield None
cp.get_default_memory_pool().free_all_blocks()
cp.get_default_pinned_memory_pool().free_all_blocks()
def force_clean_gpu_memory():
gc.collect()
cp.get_default_memory_pool().free_all_blocks()
cp.get_default_pinned_memory_pool().free_all_blocks()