MCPcopy Index your code
hub / github.com/python/cpython / train_dict

Function train_dict

Lib/compression/zstd/__init__.py:78–96  ·  view source on GitHub ↗

Return a ZstdDict representing a trained Zstandard dictionary. *samples* is an iterable of samples, where a sample is a bytes-like object representing a file. *dict_size* is the dictionary's maximum size, in bytes.

(samples, dict_size)

Source from the content-addressed store, hash-verified

76
77
78def train_dict(samples, dict_size):
79 """Return a ZstdDict representing a trained Zstandard dictionary.
80
81 *samples* is an iterable of samples, where a sample is a bytes-like
82 object representing a file.
83
84 *dict_size* is the dictionary's maximum size, in bytes.
85 """
86 if not isinstance(dict_size, int):
87 ds_cls = type(dict_size).__qualname__
88 raise TypeError(f'dict_size must be an int object, not {ds_cls!r}.')
89
90 samples = tuple(samples)
91 chunks = b''.join(samples)
92 chunk_sizes = tuple(_nbytes(sample) for sample in samples)
93 if not chunks:
94 raise ValueError("samples contained no data; can't train dictionary.")
95 dict_content = _zstd.train_dict(chunks, chunk_sizes, dict_size)
96 return ZstdDict(dict_content)
97
98
99def finalize_dict(zstd_dict, /, samples, dict_size, level):

Callers 3

setUpModuleFunction · 0.90
test_train_dictMethod · 0.90

Calls 2

_nbytesFunction · 0.90
joinMethod · 0.45

Tested by 3

setUpModuleFunction · 0.72
test_train_dictMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…