MCPcopy Create free account
hub / github.com/bamler-lab/constriction / test_ans_seek

Function test_ans_seek

tests/python/test_docexamples.py:403–425  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

401
402
403def test_ans_seek():
404 probabilities = np.array([0.2, 0.4, 0.1, 0.3], dtype=np.float64)
405 model = constriction.stream.model.Categorical(probabilities, perfect=False)
406 message_part1 = np.array([1, 2, 0, 3, 2, 3, 0], dtype=np.int32)
407 message_part2 = np.array([2, 2, 0, 1, 3], dtype=np.int32)
408
409 # Encode both parts of the message (in reverse order, because ANS
410 # operates as a stack) and record a checkpoint in-between:
411 coder = constriction.stream.stack.AnsCoder()
412 coder.encode_reverse(message_part2, model)
413 (position, state) = coder.pos() # Records a checkpoint.
414 coder.encode_reverse(message_part1, model)
415
416 # We could now call `coder.get_compressed()` but we'll just decode
417 # directly from the original `coder` for simplicity.
418
419 # Decode first symbol:
420 assert coder.decode(model) == 1
421
422 # Jump to part 2 and decode it:
423 coder.seek(position, state)
424 decoded_part2 = coder.decode(model, 5)
425 assert np.all(decoded_part2 == message_part2)
426
427
428def test_range_coding_mod():

Callers

nothing calls this directly

Calls 4

encode_reverseMethod · 0.95
posMethod · 0.95
decodeMethod · 0.95
seekMethod · 0.95

Tested by

no test coverage detected