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

Function test_old_module_example2

tests/python/test_docexamples_f32.py:474–500  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

472
473
474def test_old_module_example2():
475 # Create an empty Range Encoder:
476 encoder = constriction.stream.queue.RangeEncoder()
477
478 # Same made up data and entropy models as in the ANS Coding example above:
479 model = constriction.stream.model.QuantizedGaussian(-100, 100)
480 symbols = np.array([23, -15, 78, 43, -69], dtype=np.int32)
481 means = np.array([35.2, -1.7, 30.1, 71.2, -75.1], dtype=np.float32)
482 stds = np.array([10.1, 25.3, 23.8, 35.4, 3.9], dtype=np.float32)
483
484 # Encode the data (this time in normal order, since Range Coding is a queue):
485 encoder.encode(symbols, model, means, stds)
486
487 print(f"Compressed size: {encoder.num_bits()} bits")
488
489 # Get the compressed bit string (sealed up to full words):
490 compressed = encoder.get_compressed()
491
492 # ... writing and reading from file same as above (skipped here) ...
493
494 # Initialize a Range Decoder from the compressed bit string:
495 decoder = constriction.stream.queue.RangeDecoder(compressed)
496
497 # Decode the data and verify it's correct:
498 reconstructed = decoder.decode(model, means, stds)
499 assert decoder.maybe_exhausted()
500 assert np.all(reconstructed == symbols)
501
502
503def test_ans_example():

Callers

nothing calls this directly

Calls 5

encodeMethod · 0.95
num_bitsMethod · 0.95
get_compressedMethod · 0.95
decodeMethod · 0.95
maybe_exhaustedMethod · 0.95

Tested by

no test coverage detected