()
| 470 | |
| 471 | |
| 472 | def test_old_module_example2(): |
| 473 | # Create an empty Range Encoder: |
| 474 | encoder = constriction.stream.queue.RangeEncoder() |
| 475 | |
| 476 | # Same made up data and entropy models as in the ANS Coding example above: |
| 477 | model = constriction.stream.model.QuantizedGaussian(-100, 100) |
| 478 | symbols = np.array([23, -15, 78, 43, -69], dtype=np.int32) |
| 479 | means = np.array([35.2, -1.7, 30.1, 71.2, -75.1], dtype=np.float64) |
| 480 | stds = np.array([10.1, 25.3, 23.8, 35.4, 3.9], dtype=np.float64) |
| 481 | |
| 482 | # Encode the data (this time in normal order, since Range Coding is a queue): |
| 483 | encoder.encode(symbols, model, means, stds) |
| 484 | |
| 485 | print(f"Compressed size: {encoder.num_bits()} bits") |
| 486 | |
| 487 | # Get the compressed bit string (sealed up to full words): |
| 488 | compressed = encoder.get_compressed() |
| 489 | |
| 490 | # ... writing and reading from file same as above (skipped here) ... |
| 491 | |
| 492 | # Initialize a Range Decoder from the compressed bit string: |
| 493 | decoder = constriction.stream.queue.RangeDecoder(compressed) |
| 494 | |
| 495 | # Decode the data and verify it's correct: |
| 496 | reconstructed = decoder.decode(model, means, stds) |
| 497 | assert decoder.maybe_exhausted() |
| 498 | assert np.all(reconstructed == symbols) |
| 499 | |
| 500 | |
| 501 | def test_ans_example(): |
nothing calls this directly
no test coverage detected