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

Function test_ans_seek

tests/python/test_lazy_f32.py:238–260  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

236
237
238def test_ans_seek():
239 probabilities = np.array([0.2, 0.4, 0.1, 0.3], dtype=np.float32)
240 model = constriction.stream.model.Categorical(probabilities, lazy=True)
241 message_part1 = np.array([1, 2, 0, 3, 2, 3, 0], dtype=np.int32)
242 message_part2 = np.array([2, 2, 0, 1, 3], dtype=np.int32)
243
244 # Encode both parts of the message (in reverse order, because ANS
245 # operates as a stack) and record a checkpoint in-between:
246 coder = constriction.stream.stack.AnsCoder()
247 coder.encode_reverse(message_part2, model)
248 (position, state) = coder.pos() # Records a checkpoint.
249 coder.encode_reverse(message_part1, model)
250
251 # We could now call `coder.get_compressed()` but we'll just decode
252 # directly from the original `coder` for simplicity.
253
254 # Decode first symbol:
255 assert coder.decode(model) == 1
256
257 # Jump to part 2 and decode it:
258 coder.seek(position, state)
259 decoded_part2 = coder.decode(model, 5)
260 assert np.all(decoded_part2 == message_part2)
261
262
263def 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