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

Function test_ans_seek

tests/python/test_lazy_f64.py:211–233  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

209
210
211def test_ans_seek():
212 probabilities = np.array([0.2, 0.4, 0.1, 0.3], dtype=np.float64)
213 model = constriction.stream.model.Categorical(probabilities, lazy=True)
214 message_part1 = np.array([1, 2, 0, 3, 2, 3, 0], dtype=np.int32)
215 message_part2 = np.array([2, 2, 0, 1, 3], dtype=np.int32)
216
217 # Encode both parts of the message (in reverse order, because ANS
218 # operates as a stack) and record a checkpoint in-between:
219 coder = constriction.stream.stack.AnsCoder()
220 coder.encode_reverse(message_part2, model)
221 (position, state) = coder.pos() # Records a checkpoint.
222 coder.encode_reverse(message_part1, model)
223
224 # We could now call `coder.get_compressed()` but we'll just decode
225 # directly from the original `coder` for simplicity.
226
227 # Decode first symbol:
228 assert coder.decode(model) == 1
229
230 # Jump to part 2 and decode it:
231 coder.seek(position, state)
232 decoded_part2 = coder.decode(model, 5)
233 assert np.all(decoded_part2 == message_part2)
234
235
236def 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