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

Function test_stack_gaussian

tests/python/test_constriction.py:32–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30
31
32def test_stack_gaussian():
33 encoder = constriction.stream.stack.AnsCoder()
34
35 model = constriction.stream.model.QuantizedGaussian(-100, 100)
36 symbols = np.array([23, -15, 78, 43, -69], dtype=np.int32)
37 means = np.array([35.2, -1.7, 30.1, 71.2, -75.1], dtype=np.float64)
38 stds = np.array([10.1, 25.3, 23.8, 35.4, 3.9], dtype=np.float64)
39
40 encoder.encode_reverse(symbols, model, means, stds)
41 assert encoder.num_bits() == 64
42 assert encoder.num_valid_bits() == 51
43 compressed = encoder.get_compressed()
44 assert np.all(compressed == np.array(
45 [1109163715, 757457], dtype=np.uint32))
46
47 decoder1 = constriction.stream.stack.AnsCoder(compressed)
48 reconstructed1 = decoder1.decode(model, means, stds)
49 assert decoder1.is_empty()
50 assert np.all(reconstructed1 == symbols)
51
52 decoder2 = encoder
53 reconstructed2 = decoder2.decode(model, means, stds)
54 assert decoder2.is_empty()
55 assert np.all(reconstructed2 == symbols)
56
57
58def test_chain_gaussian():

Callers

nothing calls this directly

Calls 7

encode_reverseMethod · 0.95
num_bitsMethod · 0.95
num_valid_bitsMethod · 0.95
get_compressedMethod · 0.95
decodeMethod · 0.95
is_emptyMethod · 0.95
is_emptyMethod · 0.45

Tested by

no test coverage detected