()
| 249 | |
| 250 | |
| 251 | def test_stack2(): |
| 252 | ans = constriction.stream.stack.AnsCoder() # No arguments => empty ANS coder |
| 253 | |
| 254 | symbols = np.array([2, -1, 0, 2, 3], dtype=np.int32) |
| 255 | min_supported_symbol, max_supported_symbol = -10, 10 # both inclusively |
| 256 | model = constriction.stream.model.QuantizedGaussian( |
| 257 | min_supported_symbol, max_supported_symbol) |
| 258 | means = np.array([2.3, -1.7, 0.1, 2.2, -5.1], dtype=np.float32) |
| 259 | stds = np.array([1.1, 5.3, 3.8, 1.4, 3.9], dtype=np.float32) |
| 260 | |
| 261 | ans.encode_reverse(symbols, model, means, stds) |
| 262 | |
| 263 | print(f"Compressed size: {ans.num_valid_bits()} bits") |
| 264 | |
| 265 | compressed = ans.get_compressed() |
| 266 | # if sys.byteorder == "big": |
| 267 | # # Convert native byte order to a consistent one (here: little endian). |
| 268 | # compressed.byteswap(inplace=True) |
| 269 | # compressed.tofile("compressed.bin") |
| 270 | |
| 271 | # compressed = np.fromfile("compressed.bin", dtype=np.uint32) |
| 272 | # if sys.byteorder == "big": |
| 273 | # # Convert little endian byte order to native byte order. |
| 274 | # compressed.byteswap(inplace=True) |
| 275 | |
| 276 | ans = constriction.stream.stack.AnsCoder(compressed) |
| 277 | |
| 278 | min_supported_symbol, max_supported_symbol = -10, 10 # both inclusively |
| 279 | model = constriction.stream.model.QuantizedGaussian( |
| 280 | min_supported_symbol, max_supported_symbol) |
| 281 | means = np.array([2.3, -1.7, 0.1, 2.2, -5.1], dtype=np.float32) |
| 282 | stds = np.array([1.1, 5.3, 3.8, 1.4, 3.9], dtype=np.float32) |
| 283 | |
| 284 | reconstructed = ans.decode(model, means, stds) |
| 285 | assert ans.is_empty() |
| 286 | assert np.all(reconstructed == symbols) |
| 287 | |
| 288 | |
| 289 | def test_ans_decode1(): |
nothing calls this directly
no test coverage detected