()
| 374 | |
| 375 | |
| 376 | def test_range_coding_seek(): |
| 377 | probabilities = np.array([0.2, 0.4, 0.1, 0.3], dtype=np.float32) |
| 378 | model = constriction.stream.model.Categorical(probabilities, lazy=True) |
| 379 | message_part1 = np.array([1, 2, 0, 3, 2, 3, 0], dtype=np.int32) |
| 380 | message_part2 = np.array([2, 2, 0, 1, 3], dtype=np.int32) |
| 381 | |
| 382 | # Encode both parts of the message and record a checkpoint in-between: |
| 383 | encoder = constriction.stream.queue.RangeEncoder() |
| 384 | encoder.encode(message_part1, model) |
| 385 | (position, state) = encoder.pos() # Records a checkpoint. |
| 386 | encoder.encode(message_part2, model) |
| 387 | |
| 388 | compressed = encoder.get_compressed() |
| 389 | decoder = constriction.stream.queue.RangeDecoder(compressed) |
| 390 | |
| 391 | # Decode first symbol: |
| 392 | assert decoder.decode(model) == 1 |
| 393 | |
| 394 | # Jump to part 2 and decode it: |
| 395 | decoder.seek(position, state) |
| 396 | decoded_part2 = decoder.decode(model, 5) |
| 397 | assert np.all(decoded_part2 == message_part2) |
| 398 | |
| 399 | |
| 400 | def test_range_coding_decode4(): |
nothing calls this directly
no test coverage detected