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

Function test_module_example1

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

Source from the content-addressed store, hash-verified

5
6
7def test_module_example1():
8 message = np.array([6, 10, -4, 2, 5, 2, 1, 0, 2], dtype=np.int32)
9
10 # Define an i.i.d. entropy model (see below for more complex models):
11 entropy_model = constriction.stream.model.QuantizedGaussian(
12 -50, 50, 3.2, 9.6)
13
14 # Let's use an ANS coder in this example. See below for a Range Coder example.
15 encoder = constriction.stream.stack.AnsCoder()
16 encoder.encode_reverse(message, entropy_model)
17
18 compressed = encoder.get_compressed()
19 print(f"compressed representation: {compressed}")
20 print(f"(in binary: {[bin(word) for word in compressed]})")
21
22 decoder = constriction.stream.stack.AnsCoder(compressed)
23 decoded = decoder.decode(entropy_model, 9) # (decodes 9 symbols)
24 assert np.all(decoded == message)
25
26
27def test_module_example2():

Callers

nothing calls this directly

Calls 3

encode_reverseMethod · 0.95
get_compressedMethod · 0.95
decodeMethod · 0.95

Tested by

no test coverage detected