()
| 501 | |
| 502 | |
| 503 | def test_ans_example(): |
| 504 | ans = constriction.stream.stack.AnsCoder() # No arguments => empty ANS coder |
| 505 | |
| 506 | model = constriction.stream.model.QuantizedGaussian(-10, 10) |
| 507 | symbols = np.array([2, -1, 0, 2, 3], dtype=np.int32) |
| 508 | means = np.array([2.3, -1.7, 0.1, 2.2, -5.1], dtype=np.float32) |
| 509 | stds = np.array([1.1, 5.3, 3.8, 1.4, 3.9], dtype=np.float32) |
| 510 | |
| 511 | ans.encode_reverse(symbols, model, means, stds) |
| 512 | |
| 513 | print(f"Compressed size: {ans.num_valid_bits()} bits") |
| 514 | |
| 515 | compressed = ans.get_compressed() |
| 516 | if sys.byteorder == "big": |
| 517 | # Convert native byte order to a consistent one (here: little endian). |
| 518 | compressed.byteswap(inplace=True) |
| 519 | |
| 520 | if sys.byteorder == "big": |
| 521 | # Convert little endian byte order to native byte order. |
| 522 | compressed.byteswap(inplace=True) |
| 523 | |
| 524 | ans = constriction.stream.stack.AnsCoder(compressed) |
| 525 | |
| 526 | min_supported_symbol, max_supported_symbol = -10, 10 # both inclusively |
| 527 | means = np.array([2.3, -1.7, 0.1, 2.2, -5.1], dtype=np.float32) |
| 528 | stds = np.array([1.1, 5.3, 3.8, 1.4, 3.9], dtype=np.float32) |
| 529 | |
| 530 | reconstructed = ans.decode(model, means, stds) |
| 531 | assert ans.is_empty() |
| 532 | assert np.all(reconstructed == symbols) |
| 533 | |
| 534 | |
| 535 | def test_range_coder_encode1(): |
nothing calls this directly
no test coverage detected