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

Function test_ans_encode_reverse4

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

Source from the content-addressed store, hash-verified

385
386
387def test_ans_encode_reverse4():
388 # Define 2 categorical models over the alphabet {0, 1, 2, 3, 4}:
389 probabilities = np.array(
390 [[0.1, 0.2, 0.3, 0.1, 0.3], # (for symbols[0])
391 [0.3, 0.2, 0.2, 0.2, 0.1]], # (for symbols[1])
392 dtype=np.float64)
393 model_family = constriction.stream.model.Categorical(perfect=False)
394
395 # Encode 2 symbols (needs `len(symbols) == probabilities.shape[0]`):
396 symbols = np.array([3, 1], dtype=np.int32)
397 coder = constriction.stream.stack.AnsCoder()
398 coder.encode_reverse(symbols, model_family, probabilities)
399 assert np.all(coder.get_compressed() == np.array(
400 [45298481], dtype=np.uint32))
401
402
403def test_ans_seek():

Callers

nothing calls this directly

Calls 2

encode_reverseMethod · 0.95
get_compressedMethod · 0.95

Tested by

no test coverage detected