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

Function test_ans_seek

tests/python/test_docexamples_f32.py:405–427  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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