()
| 5 | |
| 6 | |
| 7 | def test_module_example1(): |
| 8 | message = np.array([6, 10, -4, 2, 5, 2, 1, 0, 2], dtype=np.int32) |
| 9 | |
| 10 | # Define an i.i.d. entropy model (see below for more complex models): |
| 11 | entropy_model = constriction.stream.model.QuantizedGaussian( |
| 12 | -50, 50, 3.2, 9.6) |
| 13 | |
| 14 | # Let's use an ANS coder in this example. See below for a Range Coder example. |
| 15 | encoder = constriction.stream.stack.AnsCoder() |
| 16 | encoder.encode_reverse(message, entropy_model) |
| 17 | |
| 18 | compressed = encoder.get_compressed() |
| 19 | print(f"compressed representation: {compressed}") |
| 20 | print(f"(in binary: {[bin(word) for word in compressed]})") |
| 21 | |
| 22 | decoder = constriction.stream.stack.AnsCoder(compressed) |
| 23 | decoded = decoder.decode(entropy_model, 9) # (decodes 9 symbols) |
| 24 | assert np.all(decoded == message) |
| 25 | |
| 26 | |
| 27 | def test_module_example2(): |
nothing calls this directly
no test coverage detected