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

Function test_range_coder_encode4

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

Source from the content-addressed store, hash-verified

574
575
576def test_range_coder_encode4():
577 # Define 2 categorical models over the alphabet {0, 1, 2, 3, 4}:
578 probabilities = np.array(
579 [[0.1, 0.2, 0.3, 0.1, 0.3], # (for first encoded symbol)
580 [0.3, 0.2, 0.2, 0.2, 0.1]], # (for second encoded symbol)
581 dtype=np.float64)
582 model_family = constriction.stream.model.Categorical(perfect=False)
583
584 # Encode 2 symbols (needs `len(symbols) == probabilities.shape[0]`):
585 symbols = np.array([3, 1], dtype=np.int32)
586 encoder = constriction.stream.queue.RangeEncoder()
587 encoder.encode(symbols, model_family, probabilities)
588 assert np.all(encoder.get_compressed() ==
589 np.array([2705829254], dtype=np.uint32))
590
591
592def test_range_coding_decode1():

Callers

nothing calls this directly

Calls 2

encodeMethod · 0.95
get_compressedMethod · 0.95

Tested by

no test coverage detected