-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomated_tests.py
111 lines (95 loc) · 2.41 KB
/
automated_tests.py
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
import numpy as np
import zfpc
import pytest
@pytest.fixture(scope="session")
def vector_img():
try:
return np.load("vector_field_sample.npy")
except FileNotFoundError:
with open("vector_field_sample.npy.zfpc", "rb") as f:
return zfpc.decompress(f.read())
@pytest.mark.parametrize("correlated_dims", [[True,True,True,True], [True,True,False,False], [False,True,True,True]])
@pytest.mark.parametrize("order", ['C', 'F'])
@pytest.mark.parametrize("tolerance", [ -1, 0.000002, 0.0001, 0.01 ])
def test_compression_decompression_fixed_accuracy(vector_img, correlated_dims, order, tolerance):
if order == "C":
vector_img = np.ascontiguousarray(vector_img)
else:
vector_img = np.asfortranarray(vector_img)
compressed = zfpc.compress(
vector_img,
tolerance=tolerance,
correlated_dims=correlated_dims
)
recovered = zfpc.decompress(compressed)
print(f"compression ratio: {len(compressed)/vector_img.nbytes*100:.3f}%")
atol = tolerance
if tolerance == -1:
atol = 0
assert np.allclose(recovered, vector_img, atol=atol)
@pytest.mark.parametrize("correlated_dims", [[True,True,True,True], [True,True,False,False], [False,True,True,True]])
@pytest.mark.parametrize("order", ['C', 'F'])
@pytest.mark.parametrize("rate", [ 8, 10, 12 ])
def test_compression_decompression_fixed_rate(vector_img, correlated_dims, order, rate):
if order == "C":
vector_img = np.ascontiguousarray(vector_img)
else:
vector_img = np.asfortranarray(vector_img)
compressed = zfpc.compress(
vector_img,
rate=rate,
correlated_dims=correlated_dims
)
recovered = zfpc.decompress(compressed)
print(len(compressed) / vector_img.nbytes)
print(np.max(np.abs(recovered - vector_img)))
def test_failed_arg_combo(vector_img):
compressed = zfpc.compress(
vector_img,
rate=8,
)
compressed = zfpc.compress(
vector_img,
tolerance=0.01,
)
compressed = zfpc.compress(
vector_img,
precision=5,
)
try:
compressed = zfpc.compress(
vector_img,
tolerance=0.01,
rate=8,
)
assert False
except ValueError:
pass
try:
compressed = zfpc.compress(
vector_img,
tolerance=0.01,
precision=8,
)
assert False
except ValueError:
pass
try:
compressed = zfpc.compress(
vector_img,
precision=0.01,
rate=8,
)
assert False
except ValueError:
pass
try:
compressed = zfpc.compress(
vector_img,
tolerance=0.01,
rate=8,
precision=5,
)
assert False
except ValueError:
pass