()
| 30 | |
| 31 | |
| 32 | def 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 | |
| 58 | def test_chain_gaussian(): |
nothing calls this directly
no test coverage detected