naw 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- naw/__init__.py +0 -0
- naw/_bfloat16.pyi +13 -0
- naw/_float16.pyi +11 -0
- naw/_float32.pyi +11 -0
- naw/_float64.pyi +11 -0
- naw/_leb.pyi +6 -0
- naw/bench_bfloat16.py +69 -0
- naw/bench_byteio.py +241 -0
- naw/bench_float16.py +38 -0
- naw/bench_float32.py +38 -0
- naw/bench_float64.py +38 -0
- naw/bench_leb.py +62 -0
- naw/bfloat16.py +53 -0
- naw/byteio.py +310 -0
- naw/chunk.py +161 -0
- naw/cli.py +513 -0
- naw/exceptions.py +10 -0
- naw/float16.py +33 -0
- naw/float32.py +33 -0
- naw/float64.py +33 -0
- naw/leb.py +72 -0
- naw/rtsdb.py +1291 -0
- naw/test_bfloat16.py +39 -0
- naw/test_byteio.py +262 -0
- naw/test_chunk.py +190 -0
- naw/test_float16.py +19 -0
- naw/test_float32.py +19 -0
- naw/test_float64.py +19 -0
- naw/test_leb.py +51 -0
- naw/test_rtsdb.py +312 -0
- naw/test_wandb.py +460 -0
- naw/utils.py +19 -0
- naw/wandb.py +509 -0
- naw-0.0.1.dist-info/METADATA +28 -0
- naw-0.0.1.dist-info/RECORD +39 -0
- naw-0.0.1.dist-info/WHEEL +5 -0
- naw-0.0.1.dist-info/entry_points.txt +2 -0
- naw-0.0.1.dist-info/licenses/LICENSE +21 -0
- naw-0.0.1.dist-info/top_level.txt +1 -0
naw/__init__.py
ADDED
|
File without changes
|
naw/_bfloat16.pyi
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import collections.abc
|
|
2
|
+
|
|
3
|
+
def write_bfloat16_array(data: collections.abc.Iterable[float]) -> list[int]: ...
|
|
4
|
+
def write_bfloat16_xor_array(
|
|
5
|
+
values: collections.abc.Iterable[float],
|
|
6
|
+
previous_values: collections.abc.Iterable[float],
|
|
7
|
+
) -> list[int]: ...
|
|
8
|
+
def read_bfloat16_array(data: bytes, n: int) -> tuple[int, list[float]]: ...
|
|
9
|
+
def read_bfloat16_xor_array(
|
|
10
|
+
data: bytes,
|
|
11
|
+
n: int,
|
|
12
|
+
previous_values: collections.abc.Sequence[float],
|
|
13
|
+
) -> tuple[int, list[float]]: ...
|
naw/_float16.pyi
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import collections.abc
|
|
2
|
+
|
|
3
|
+
def write_float16_xor_array(
|
|
4
|
+
values: collections.abc.Iterable[float],
|
|
5
|
+
previous_values: collections.abc.Iterable[float],
|
|
6
|
+
) -> list[int]: ...
|
|
7
|
+
def read_float16_xor_array(
|
|
8
|
+
data: bytes,
|
|
9
|
+
n: int,
|
|
10
|
+
previous_values: collections.abc.Sequence[float],
|
|
11
|
+
) -> tuple[int, list[float]]: ...
|
naw/_float32.pyi
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import collections.abc
|
|
2
|
+
|
|
3
|
+
def write_float32_xor_array(
|
|
4
|
+
values: collections.abc.Iterable[float],
|
|
5
|
+
previous_values: collections.abc.Iterable[float],
|
|
6
|
+
) -> list[int]: ...
|
|
7
|
+
def read_float32_xor_array(
|
|
8
|
+
data: bytes,
|
|
9
|
+
n: int,
|
|
10
|
+
previous_values: collections.abc.Sequence[float],
|
|
11
|
+
) -> tuple[int, list[float]]: ...
|
naw/_float64.pyi
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import collections.abc
|
|
2
|
+
|
|
3
|
+
def write_float64_xor_array(
|
|
4
|
+
values: collections.abc.Iterable[float],
|
|
5
|
+
previous_values: collections.abc.Iterable[float],
|
|
6
|
+
) -> list[int]: ...
|
|
7
|
+
def read_float64_xor_array(
|
|
8
|
+
data: bytes,
|
|
9
|
+
n: int,
|
|
10
|
+
previous_values: collections.abc.Sequence[float],
|
|
11
|
+
) -> tuple[int, list[float]]: ...
|
naw/_leb.pyi
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import collections.abc
|
|
2
|
+
|
|
3
|
+
def read_unsigned_array(data: bytes, n: int) -> tuple[int, list[int]]: ...
|
|
4
|
+
def read_signed_array(data: bytes, n: int) -> tuple[int, list[int]]: ...
|
|
5
|
+
def write_unsigned_array(data: collections.abc.Iterable[int]) -> list[int]: ...
|
|
6
|
+
def write_signed_array(data: collections.abc.Iterable[int]) -> list[int]: ...
|
naw/bench_bfloat16.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
import pytest_benchmark.fixture
|
|
3
|
+
|
|
4
|
+
from . import bfloat16
|
|
5
|
+
|
|
6
|
+
N = 1000
|
|
7
|
+
|
|
8
|
+
_float_values = [float(i) for i in range(N)]
|
|
9
|
+
_float_prev_values = [float(i) for i in range(-1, N - 1)]
|
|
10
|
+
_bf16_data = bytes(bfloat16.write_bfloat16_array(_float_values))
|
|
11
|
+
_bf16_xor_data = bytes(
|
|
12
|
+
bfloat16.write_bfloat16_xor_array(_float_values, _float_prev_values)
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_py_write_bfloat16_array(
|
|
17
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
18
|
+
) -> None:
|
|
19
|
+
benchmark(lambda: bfloat16.write_bfloat16_array(_float_values))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_py_read_bfloat16_array(
|
|
23
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
24
|
+
) -> None:
|
|
25
|
+
benchmark(lambda: bfloat16.read_bfloat16_array(_bf16_data, N))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_py_write_bfloat16_xor_array(
|
|
29
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
30
|
+
) -> None:
|
|
31
|
+
benchmark(
|
|
32
|
+
lambda: bfloat16.write_bfloat16_xor_array(_float_values, _float_prev_values)
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_py_read_bfloat16_xor_array(
|
|
37
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
38
|
+
) -> None:
|
|
39
|
+
benchmark(
|
|
40
|
+
lambda: bfloat16.read_bfloat16_xor_array(_bf16_xor_data, N, _float_prev_values)
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_cy_write_bfloat16_array(
|
|
45
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
46
|
+
) -> None:
|
|
47
|
+
cy = pytest.importorskip("baw._bfloat16")
|
|
48
|
+
benchmark(lambda: cy.write_bfloat16_array(_float_values))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_cy_read_bfloat16_array(
|
|
52
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
53
|
+
) -> None:
|
|
54
|
+
cy = pytest.importorskip("baw._bfloat16")
|
|
55
|
+
benchmark(lambda: cy.read_bfloat16_array(_bf16_data, N))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_cy_write_bfloat16_xor_array(
|
|
59
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
60
|
+
) -> None:
|
|
61
|
+
cy = pytest.importorskip("baw._bfloat16")
|
|
62
|
+
benchmark(lambda: cy.write_bfloat16_xor_array(_float_values, _float_prev_values))
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_cy_read_bfloat16_xor_array(
|
|
66
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
67
|
+
) -> None:
|
|
68
|
+
cy = pytest.importorskip("baw._bfloat16")
|
|
69
|
+
benchmark(lambda: cy.read_bfloat16_xor_array(_bf16_xor_data, N, _float_prev_values))
|
naw/bench_byteio.py
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import pytest_benchmark.fixture
|
|
2
|
+
|
|
3
|
+
from . import byteio
|
|
4
|
+
|
|
5
|
+
N = 1000
|
|
6
|
+
|
|
7
|
+
_int_values = list(range(N))
|
|
8
|
+
_float_values = [float(i) for i in range(N)]
|
|
9
|
+
_float_prev_values = [float(i) for i in range(-1, N - 1)]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_write_sleb_array(benchmark: pytest_benchmark.fixture.BenchmarkFixture) -> None:
|
|
13
|
+
def run() -> None:
|
|
14
|
+
w = byteio.Writer()
|
|
15
|
+
w.write_sleb_array(_int_values)
|
|
16
|
+
|
|
17
|
+
benchmark(run)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_read_sleb_array(benchmark: pytest_benchmark.fixture.BenchmarkFixture) -> None:
|
|
21
|
+
w = byteio.Writer()
|
|
22
|
+
w.write_sleb_array(_int_values)
|
|
23
|
+
data = w.bytes
|
|
24
|
+
|
|
25
|
+
def run() -> None:
|
|
26
|
+
r = byteio.Reader(data)
|
|
27
|
+
r.read_sleb_array(N)
|
|
28
|
+
|
|
29
|
+
benchmark(run)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_write_uleb_array(benchmark: pytest_benchmark.fixture.BenchmarkFixture) -> None:
|
|
33
|
+
def run() -> None:
|
|
34
|
+
w = byteio.Writer()
|
|
35
|
+
w.write_uleb_array(_int_values)
|
|
36
|
+
|
|
37
|
+
benchmark(run)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_read_uleb_array(benchmark: pytest_benchmark.fixture.BenchmarkFixture) -> None:
|
|
41
|
+
w = byteio.Writer()
|
|
42
|
+
w.write_uleb_array(_int_values)
|
|
43
|
+
data = w.bytes
|
|
44
|
+
|
|
45
|
+
def run() -> None:
|
|
46
|
+
r = byteio.Reader(data)
|
|
47
|
+
r.read_uleb_array(N)
|
|
48
|
+
|
|
49
|
+
benchmark(run)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_write_float16_array(
|
|
53
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
54
|
+
) -> None:
|
|
55
|
+
def run() -> None:
|
|
56
|
+
w = byteio.Writer()
|
|
57
|
+
w.write_float16_array(_float_values)
|
|
58
|
+
|
|
59
|
+
benchmark(run)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_read_float16_array(
|
|
63
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
64
|
+
) -> None:
|
|
65
|
+
w = byteio.Writer()
|
|
66
|
+
w.write_float16_array(_float_values)
|
|
67
|
+
data = w.bytes
|
|
68
|
+
|
|
69
|
+
def run() -> None:
|
|
70
|
+
r = byteio.Reader(data)
|
|
71
|
+
r.read_float16_array(N)
|
|
72
|
+
|
|
73
|
+
benchmark(run)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def test_write_float16_xor_array(
|
|
77
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
78
|
+
) -> None:
|
|
79
|
+
def run() -> None:
|
|
80
|
+
w = byteio.Writer()
|
|
81
|
+
w.write_float16_xor_array(_float_values, _float_prev_values)
|
|
82
|
+
|
|
83
|
+
benchmark(run)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def test_read_float16_xor_array(
|
|
87
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
88
|
+
) -> None:
|
|
89
|
+
w = byteio.Writer()
|
|
90
|
+
w.write_float16_xor_array(_float_values, _float_prev_values)
|
|
91
|
+
data = w.bytes
|
|
92
|
+
|
|
93
|
+
def run() -> None:
|
|
94
|
+
r = byteio.Reader(data)
|
|
95
|
+
r.read_float16_xor_array(N, _float_prev_values)
|
|
96
|
+
|
|
97
|
+
benchmark(run)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_write_bfloat16_array(
|
|
101
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
102
|
+
) -> None:
|
|
103
|
+
def run() -> None:
|
|
104
|
+
w = byteio.Writer()
|
|
105
|
+
w.write_bfloat16_array(_float_values)
|
|
106
|
+
|
|
107
|
+
benchmark(run)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_read_bfloat16_array(
|
|
111
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
112
|
+
) -> None:
|
|
113
|
+
w = byteio.Writer()
|
|
114
|
+
w.write_bfloat16_array(_float_values)
|
|
115
|
+
data = w.bytes
|
|
116
|
+
|
|
117
|
+
def run() -> None:
|
|
118
|
+
r = byteio.Reader(data)
|
|
119
|
+
r.read_bfloat16_array(N)
|
|
120
|
+
|
|
121
|
+
benchmark(run)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def test_write_bfloat16_xor_array(
|
|
125
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
126
|
+
) -> None:
|
|
127
|
+
def run() -> None:
|
|
128
|
+
w = byteio.Writer()
|
|
129
|
+
w.write_bfloat16_xor_array(_float_values, _float_prev_values)
|
|
130
|
+
|
|
131
|
+
benchmark(run)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def test_read_bfloat16_xor_array(
|
|
135
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
136
|
+
) -> None:
|
|
137
|
+
w = byteio.Writer()
|
|
138
|
+
w.write_bfloat16_xor_array(_float_values, _float_prev_values)
|
|
139
|
+
data = w.bytes
|
|
140
|
+
|
|
141
|
+
def run() -> None:
|
|
142
|
+
r = byteio.Reader(data)
|
|
143
|
+
r.read_bfloat16_xor_array(N, _float_prev_values)
|
|
144
|
+
|
|
145
|
+
benchmark(run)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def test_write_float32_array(
|
|
149
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
150
|
+
) -> None:
|
|
151
|
+
def run() -> None:
|
|
152
|
+
w = byteio.Writer()
|
|
153
|
+
w.write_float32_array(_float_values)
|
|
154
|
+
|
|
155
|
+
benchmark(run)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def test_read_float32_array(
|
|
159
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
160
|
+
) -> None:
|
|
161
|
+
w = byteio.Writer()
|
|
162
|
+
w.write_float32_array(_float_values)
|
|
163
|
+
data = w.bytes
|
|
164
|
+
|
|
165
|
+
def run() -> None:
|
|
166
|
+
r = byteio.Reader(data)
|
|
167
|
+
r.read_float32_array(N)
|
|
168
|
+
|
|
169
|
+
benchmark(run)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def test_write_float32_xor_array(
|
|
173
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
174
|
+
) -> None:
|
|
175
|
+
def run() -> None:
|
|
176
|
+
w = byteio.Writer()
|
|
177
|
+
w.write_float32_xor_array(_float_values, _float_prev_values)
|
|
178
|
+
|
|
179
|
+
benchmark(run)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def test_read_float32_xor_array(
|
|
183
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
184
|
+
) -> None:
|
|
185
|
+
w = byteio.Writer()
|
|
186
|
+
w.write_float32_xor_array(_float_values, _float_prev_values)
|
|
187
|
+
data = w.bytes
|
|
188
|
+
|
|
189
|
+
def run() -> None:
|
|
190
|
+
r = byteio.Reader(data)
|
|
191
|
+
r.read_float32_xor_array(N, _float_prev_values)
|
|
192
|
+
|
|
193
|
+
benchmark(run)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def test_write_float64_array(
|
|
197
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
198
|
+
) -> None:
|
|
199
|
+
def run() -> None:
|
|
200
|
+
w = byteio.Writer()
|
|
201
|
+
w.write_float64_array(_float_values)
|
|
202
|
+
|
|
203
|
+
benchmark(run)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def test_read_float64_array(
|
|
207
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
208
|
+
) -> None:
|
|
209
|
+
w = byteio.Writer()
|
|
210
|
+
w.write_float64_array(_float_values)
|
|
211
|
+
data = w.bytes
|
|
212
|
+
|
|
213
|
+
def run() -> None:
|
|
214
|
+
r = byteio.Reader(data)
|
|
215
|
+
r.read_float64_array(N)
|
|
216
|
+
|
|
217
|
+
benchmark(run)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def test_write_float64_xor_array(
|
|
221
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
222
|
+
) -> None:
|
|
223
|
+
def run() -> None:
|
|
224
|
+
w = byteio.Writer()
|
|
225
|
+
w.write_float64_xor_array(_float_values, _float_prev_values)
|
|
226
|
+
|
|
227
|
+
benchmark(run)
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def test_read_float64_xor_array(
|
|
231
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
232
|
+
) -> None:
|
|
233
|
+
w = byteio.Writer()
|
|
234
|
+
w.write_float64_xor_array(_float_values, _float_prev_values)
|
|
235
|
+
data = w.bytes
|
|
236
|
+
|
|
237
|
+
def run() -> None:
|
|
238
|
+
r = byteio.Reader(data)
|
|
239
|
+
r.read_float64_xor_array(N, _float_prev_values)
|
|
240
|
+
|
|
241
|
+
benchmark(run)
|
naw/bench_float16.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
import pytest_benchmark.fixture
|
|
3
|
+
|
|
4
|
+
from . import float16
|
|
5
|
+
|
|
6
|
+
N = 1000
|
|
7
|
+
|
|
8
|
+
_float_values = [float(i) for i in range(N)]
|
|
9
|
+
_float_prev_values = [float(i) for i in range(-1, N - 1)]
|
|
10
|
+
_xor_data = bytes(float16.write_float16_xor_array(_float_values, _float_prev_values))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_py_write_float16_xor_array(
|
|
14
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
15
|
+
) -> None:
|
|
16
|
+
benchmark(
|
|
17
|
+
lambda: float16.write_float16_xor_array(_float_values, _float_prev_values)
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_py_read_float16_xor_array(
|
|
22
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
23
|
+
) -> None:
|
|
24
|
+
benchmark(lambda: float16.read_float16_xor_array(_xor_data, N, _float_prev_values))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_cy_write_float16_xor_array(
|
|
28
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
29
|
+
) -> None:
|
|
30
|
+
cy = pytest.importorskip("baw._float16")
|
|
31
|
+
benchmark(lambda: cy.write_float16_xor_array(_float_values, _float_prev_values))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_cy_read_float16_xor_array(
|
|
35
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
36
|
+
) -> None:
|
|
37
|
+
cy = pytest.importorskip("baw._float16")
|
|
38
|
+
benchmark(lambda: cy.read_float16_xor_array(_xor_data, N, _float_prev_values))
|
naw/bench_float32.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
import pytest_benchmark.fixture
|
|
3
|
+
|
|
4
|
+
from . import float32
|
|
5
|
+
|
|
6
|
+
N = 1000
|
|
7
|
+
|
|
8
|
+
_float_values = [float(i) for i in range(N)]
|
|
9
|
+
_float_prev_values = [float(i) for i in range(-1, N - 1)]
|
|
10
|
+
_xor_data = bytes(float32.write_float32_xor_array(_float_values, _float_prev_values))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_py_write_float32_xor_array(
|
|
14
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
15
|
+
) -> None:
|
|
16
|
+
benchmark(
|
|
17
|
+
lambda: float32.write_float32_xor_array(_float_values, _float_prev_values)
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_py_read_float32_xor_array(
|
|
22
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
23
|
+
) -> None:
|
|
24
|
+
benchmark(lambda: float32.read_float32_xor_array(_xor_data, N, _float_prev_values))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_cy_write_float32_xor_array(
|
|
28
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
29
|
+
) -> None:
|
|
30
|
+
cy = pytest.importorskip("baw._float32")
|
|
31
|
+
benchmark(lambda: cy.write_float32_xor_array(_float_values, _float_prev_values))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_cy_read_float32_xor_array(
|
|
35
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
36
|
+
) -> None:
|
|
37
|
+
cy = pytest.importorskip("baw._float32")
|
|
38
|
+
benchmark(lambda: cy.read_float32_xor_array(_xor_data, N, _float_prev_values))
|
naw/bench_float64.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
import pytest_benchmark.fixture
|
|
3
|
+
|
|
4
|
+
from . import float64
|
|
5
|
+
|
|
6
|
+
N = 1000
|
|
7
|
+
|
|
8
|
+
_float_values = [float(i) for i in range(N)]
|
|
9
|
+
_float_prev_values = [float(i) for i in range(-1, N - 1)]
|
|
10
|
+
_xor_data = bytes(float64.write_float64_xor_array(_float_values, _float_prev_values))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_py_write_float64_xor_array(
|
|
14
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
15
|
+
) -> None:
|
|
16
|
+
benchmark(
|
|
17
|
+
lambda: float64.write_float64_xor_array(_float_values, _float_prev_values)
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_py_read_float64_xor_array(
|
|
22
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
23
|
+
) -> None:
|
|
24
|
+
benchmark(lambda: float64.read_float64_xor_array(_xor_data, N, _float_prev_values))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_cy_write_float64_xor_array(
|
|
28
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
29
|
+
) -> None:
|
|
30
|
+
cy = pytest.importorskip("baw._float64")
|
|
31
|
+
benchmark(lambda: cy.write_float64_xor_array(_float_values, _float_prev_values))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_cy_read_float64_xor_array(
|
|
35
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
36
|
+
) -> None:
|
|
37
|
+
cy = pytest.importorskip("baw._float64")
|
|
38
|
+
benchmark(lambda: cy.read_float64_xor_array(_xor_data, N, _float_prev_values))
|
naw/bench_leb.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
import pytest_benchmark.fixture
|
|
3
|
+
|
|
4
|
+
from . import leb
|
|
5
|
+
|
|
6
|
+
N = 1000
|
|
7
|
+
|
|
8
|
+
_int_values = list(range(N))
|
|
9
|
+
_uleb_data = bytes(leb.write_unsigned_array(_int_values))
|
|
10
|
+
_sleb_data = bytes(leb.write_signed_array(_int_values))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_py_write_uleb_array(
|
|
14
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
15
|
+
) -> None:
|
|
16
|
+
benchmark(lambda: leb.write_unsigned_array(_int_values))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def test_py_read_uleb_array(
|
|
20
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
21
|
+
) -> None:
|
|
22
|
+
benchmark(lambda: leb.read_unsigned_array(_uleb_data, N))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_py_write_sleb_array(
|
|
26
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
27
|
+
) -> None:
|
|
28
|
+
benchmark(lambda: leb.write_signed_array(_int_values))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_py_read_sleb_array(
|
|
32
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
33
|
+
) -> None:
|
|
34
|
+
benchmark(lambda: leb.read_signed_array(_sleb_data, N))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_cy_write_uleb_array(
|
|
38
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
39
|
+
) -> None:
|
|
40
|
+
cy = pytest.importorskip("baw._leb")
|
|
41
|
+
benchmark(lambda: cy.write_unsigned_array(_int_values))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_cy_read_uleb_array(
|
|
45
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
46
|
+
) -> None:
|
|
47
|
+
cy = pytest.importorskip("baw._leb")
|
|
48
|
+
benchmark(lambda: cy.read_unsigned_array(_uleb_data, N))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_cy_write_sleb_array(
|
|
52
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
53
|
+
) -> None:
|
|
54
|
+
cy = pytest.importorskip("baw._leb")
|
|
55
|
+
benchmark(lambda: cy.write_signed_array(_int_values))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_cy_read_sleb_array(
|
|
59
|
+
benchmark: pytest_benchmark.fixture.BenchmarkFixture,
|
|
60
|
+
) -> None:
|
|
61
|
+
cy = pytest.importorskip("baw._leb")
|
|
62
|
+
benchmark(lambda: cy.read_signed_array(_sleb_data, N))
|
naw/bfloat16.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import collections.abc
|
|
2
|
+
import struct
|
|
3
|
+
|
|
4
|
+
try:
|
|
5
|
+
from . import _leb as leb
|
|
6
|
+
except ImportError:
|
|
7
|
+
from . import leb
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def write_bfloat16_array(values: collections.abc.Iterable[float]) -> list[int]:
|
|
11
|
+
result: list[int] = []
|
|
12
|
+
for v in values:
|
|
13
|
+
packed = struct.pack(">f", v)
|
|
14
|
+
result.append(packed[0])
|
|
15
|
+
result.append(packed[1])
|
|
16
|
+
return result
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def write_bfloat16_xor_array(
|
|
20
|
+
values: collections.abc.Iterable[float],
|
|
21
|
+
previous_values: collections.abc.Iterable[float],
|
|
22
|
+
) -> list[int]:
|
|
23
|
+
xored = [
|
|
24
|
+
struct.unpack(">H", struct.pack(">f", v)[:2])[0]
|
|
25
|
+
^ struct.unpack(">H", struct.pack(">f", p)[:2])[0]
|
|
26
|
+
for v, p in zip(values, previous_values)
|
|
27
|
+
]
|
|
28
|
+
return leb.write_unsigned_array(xored)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def read_bfloat16_array(data: bytes, n: int) -> tuple[int, list[float]]:
|
|
32
|
+
result: list[float] = []
|
|
33
|
+
offset = 0
|
|
34
|
+
for _ in range(n):
|
|
35
|
+
v = struct.unpack(">f", data[offset : offset + 2] + b"\x00\x00")[0]
|
|
36
|
+
result.append(v)
|
|
37
|
+
offset += 2
|
|
38
|
+
return offset, result
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def read_bfloat16_xor_array(
|
|
42
|
+
data: bytes,
|
|
43
|
+
n: int,
|
|
44
|
+
previous_values: collections.abc.Sequence[float],
|
|
45
|
+
) -> tuple[int, list[float]]:
|
|
46
|
+
offset, xored_current = leb.read_unsigned_array(data, n)
|
|
47
|
+
result: list[float] = []
|
|
48
|
+
for c, p in zip(xored_current, previous_values):
|
|
49
|
+
prev_bits = struct.unpack(">H", struct.pack(">f", p)[:2])[0]
|
|
50
|
+
curr_bits = c ^ prev_bits
|
|
51
|
+
v = struct.unpack(">f", struct.pack(">H", curr_bits) + b"\x00\x00")[0]
|
|
52
|
+
result.append(v)
|
|
53
|
+
return offset, result
|