| 657 | |
| 658 | |
| 659 | def test_range_coding_decode4(): |
| 660 | # Define 2 categorical models over the alphabet {0, 1, 2, 3, 4}: |
| 661 | probabilities = np.array( |
| 662 | [[0.1, 0.2, 0.3, 0.1, 0.3], # (for first decoded symbol) |
| 663 | [0.3, 0.2, 0.2, 0.2, 0.1]], # (for second decoded symbol) |
| 664 | dtype=np.float64) |
| 665 | model_family = constriction.stream.model.Categorical(perfect=False) |
| 666 | |
| 667 | # Decode 2 symbols: |
| 668 | compressed = np.array([2705829535], dtype=np.uint32) |
| 669 | decoder = constriction.stream.queue.RangeDecoder(compressed) |
| 670 | symbols = decoder.decode(model_family, probabilities) |
| 671 | assert np.all(symbols == np.array([3, 1], dtype=np.int32)) |
| 672 | |
| 673 | |
| 674 | def test_custom_model_ans(): |