()
| 347 | |
| 348 | |
| 349 | def test_range_coding_seek(): |
| 350 | probabilities = np.array([0.2, 0.4, 0.1, 0.3], dtype=np.float64) |
| 351 | model = constriction.stream.model.Categorical(probabilities, lazy=True) |
| 352 | message_part1 = np.array([1, 2, 0, 3, 2, 3, 0], dtype=np.int32) |
| 353 | message_part2 = np.array([2, 2, 0, 1, 3], dtype=np.int32) |
| 354 | |
| 355 | # Encode both parts of the message and record a checkpoint in-between: |
| 356 | encoder = constriction.stream.queue.RangeEncoder() |
| 357 | encoder.encode(message_part1, model) |
| 358 | (position, state) = encoder.pos() # Records a checkpoint. |
| 359 | encoder.encode(message_part2, model) |
| 360 | |
| 361 | compressed = encoder.get_compressed() |
| 362 | decoder = constriction.stream.queue.RangeDecoder(compressed) |
| 363 | |
| 364 | # Decode first symbol: |
| 365 | assert decoder.decode(model) == 1 |
| 366 | |
| 367 | # Jump to part 2 and decode it: |
| 368 | decoder.seek(position, state) |
| 369 | decoded_part2 = decoder.decode(model, 5) |
| 370 | assert np.all(decoded_part2 == message_part2) |
| 371 | |
| 372 | |
| 373 | def test_range_coding_decode4(): |
nothing calls this directly
no test coverage detected