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

Function test_module_example2

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

Source from the content-addressed store, hash-verified

25
26
27def test_module_example2():
28 # Same representation of message and entropy model as in the previous example:
29 message = np.array([6, 10, -4, 2, 5, 2, 1, 0, 2], dtype=np.int32)
30 entropy_model = constriction.stream.model.QuantizedGaussian(
31 -50, 50, 3.2, 9.6)
32
33 # Let's use a Range coder now:
34 encoder = constriction.stream.queue.RangeEncoder() # <-- CHANGED LINE
35 # <-- (slightly) CHANGED LINE
36 encoder.encode(message, entropy_model)
37
38 compressed = encoder.get_compressed()
39 print(f"compressed representation: {compressed}")
40 print(f"(in binary: {[bin(word) for word in compressed]})")
41
42 decoder = constriction.stream.queue.RangeDecoder(
43 compressed) # <--CHANGED LINE
44 decoded = decoder.decode(entropy_model, 9) # (decodes 9 symbols)
45 assert np.all(decoded == message)
46
47
48def test_old_module_example1():

Callers

nothing calls this directly

Calls 3

encodeMethod · 0.95
get_compressedMethod · 0.95
decodeMethod · 0.95

Tested by

no test coverage detected