a81e75aInitial commitJeremy Magland 1def compress_ints_lossless(x, *, method: str = "zstd") -> bytes:
5 x: NumPy array of integers to compress
6 method: Compression method to use. One of:
7 - "zstd": Zstandard compression (default)
8 - "zlib": zlib compression
9 - "lzma": LZMA compression
10 - "simple_ans": Simple Asymmetric Numeral Systems
12 Returns:
13 Compressed bytes
14 """
18 return cctx.compress(x.tobytes())
19 elif method == "zlib":
20 import zlib
21 return zlib.compress(x.tobytes(), level=9)
22 elif method == "lzma":
23 import lzma
24 return lzma.compress(x.tobytes(), preset=9)
25 elif method == "simple_ans":
26 from simple_ans import ans_encode
27 encoding = ans_encode(x)
28 return encoding.bitstream + encoding.symbol_counts.tobytes() + encoding.symbol_values.tobytes()
29 else: