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