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

Function test_stack2

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

encode_reverseMethod · 0.95
num_valid_bitsMethod · 0.95
get_compressedMethod · 0.95
decodeMethod · 0.95
is_emptyMethod · 0.95

Tested by

no test coverage detected