YAECL Yet Another Entropy Coding Library
1.0.0
pip install yaecl==0.0.1import yaecl| Platform | Coding Algo | Coding Mode | Cdf Mode | Cdf Precision Ctrl | Codec Precision Ctrl | |
|---|---|---|---|---|---|---|
| yaecl | C++ header, Python | AC, RANS | 1x1,1xn,nxn | int (any w) | Yes | Yes |
| constriction | Rust, Python | Huffman, RANGE, RANS | 1x1,1xn,nxn | float | No | No |
| torchac | Python (torch) | AC | nxn | float, int16 | No | No |
| nayuki | C++, Python, Java | AC | 1x1 | uint32 | Yes | Yes |
| ryg_rans | C header | RANS | 1x1 | uint32 | Yes | No |
| Turbo | C/C++ | RANGE, AC, rANS | 1x1 | float, int8/16/32 | Yes | Yes |
#include "yaecl.hpp"
using namespace yaecl;uint32_t cdf_max= (1 << 16);
uint32_t cdf[6] = {0, 0.2 * cdf_max, 0.4 * cdf_max, 0.6 * cdf_max, 0.8 * cdf_max, cdf_max};ArithmeticCodingEncoder<uint64_t, uint32_t> ace=ArithmeticCodingEncoder<uint64_t, uint32_t>(32);
for(int i=1;i<=test_n;i++) ace.encode(i % 5, cdf, 16);
ace.flush();
ace.bit_stream.save("path"); // optionallyBitStream bs = ace.bit_stream;
// BitStream bs; bs.load("path");
ArithmeticCodingDecoder<uint64_t, uint32_t> acd = ArithmeticCodingDecoder<uint64_t, uint32_t>(32, bs);
for(int i=1;i<=test_n;i++) assert(static_cast<int>(acd.decode(5, cdf, 16)) == i%5);mkdir build
cd build
cmake ../ -DPYTHON_EXECUTABLE:FILEPATH=$YOUR_PYTHON_BIN -DPYTHON_INCLUDE_DIR:PATH=$YOUR_PYTHON_INCLUDE -DPYTHON_LIBRARY:FILEPATH=$YOUR_PYTHON_LIB
make -jcmake ../ -DPYTHON_EXECUTABLE:FILEPATH=/home/xx/.conda/envs/yy/bin/python -DPYTHON_INCLUDE_DIR:PATH=/home/xx/.conda/envs/yy/include/python3.10 -DPYTHON_LIBRARY:FILEPATH=/home/xx/.conda/envs/yy/lib/libpython3.10.soimport yaeclcnt = 32*48*320
cdf_max = 2 ** 16
cdf = np.array([0, 0.2 * cdf_max, 0.4 * cdf_max, 0.6 * cdf_max, 0.8 * cdf_max, cdf_max], dtype=np.int32)
# encode symbol by symbol
ac_enc = yaecl.ac_encoder_t()
for i in range(cnt):
ac_enc.encode(i % 5, memoryview(cdf), 16)
ac_enc.flush()
# encode n x 1
sym_b = np.array([i % 5 for i in range(cnt)], dtype=np.int32)
symd_b = np.array([0 for _ in range(cnt)], dtype=np.int32)
ac_enc = yaecl.ac_encoder_t()
ac_enc.encode_nx1(sym_b, memoryview(cdf), 16)
ac_enc.flush()
# encode n x n
sym_b = np.array([i % 5 for i in range(cnt)], dtype=np.int32)
cdf_b = np.array([cdf for _ in range(cnt)], dtype=np.int32)
ac_enc = yaecl.ac_encoder_t()
ac_enc.encode_nxn(sym_b, cdf_b, 16)
ac_enc.flush()# decode 1 x 1
ac_dec = yaecl.ac_decoder_t(ac_enc.bit_stream)
for i in range(cnt):
de_sym = ac_dec.decode(5, memoryview(cdf), 16)
# decode n x n
symd_b = np.array([0 for _ in range(cnt)], dtype=np.int32)
ac_dec = yaecl.ac_decoder_t(ac_enc.bit_stream)
ac_dec.decode_nxn(5, memoryview(cdf_b), 16, memoryview(symd_b))@article{xu2022bit,
title={Bit allocation using optimization},
author={Xu, Tongda and Gao, Han and Gao, Chenjian and Pi, Jinyong and Li, Yanghao and Wang, Yuanyuan and Zhu, Ziyu and He, Dailan and Ye, Mao and Qin, Hongwei and others},
journal={arXiv preprint arXiv:2209.09422},
year={2022}
}