best
numcodecs_combinators.best
This module defines the PickBestCodec class, which picks the codec that encoded the data best.
Classes:
-
PickBestCodec–A codec that tries encoding with all combined codecs and then picks the one with the fewest bytes.
PickBestCodec
Bases: Codec, CodecCombinatorMixin, tuple[Codec]
A codec that tries encoding with all combined codecs and then picks the one with the fewest bytes.
The inner codecs must all encode to 1D byte arrays. To use a codec not
encoding to bytes with this combinator, you can wrap it using
FramedCodecStack(codec)
combinator.
This combinator uses the ULEB128 variable length integer encoding to encode the index of the codec that was chosen to encode and uses this index as a header before the encoded bytes. The header index is only included if this combinator wraps at least two codecs. If this combinator wraps zero codecs, it passes the original data through unchanged.
Methods:
-
encode–Encode the data in
buf. -
decode–Decode the data in
buf. -
get_config–Returns the configuration of the best codec combinator.
-
from_config–Instantiate the best codec combinator from a configuration
dict. -
map–Apply the
mapperto all codecs that are in this combinator.
encode
encode(buf: Buffer) -> bytes
Encode the data in buf.
| Parameters: |
|
|---|
| Returns: |
|
|---|
decode
decode(buf: Buffer, out: Optional[Buffer] = None) -> Buffer
Decode the data in buf.
| Parameters: |
|
|---|
| Returns: |
|
|---|
get_config
get_config() -> dict
Returns the configuration of the best codec combinator.
numcodecs.registry.get_codec(config)
can be used to reconstruct this combinator from the returned config.
| Returns: |
|
|---|
from_config
classmethod
from_config(config: dict) -> Self
Instantiate the best codec combinator from a configuration dict.
| Parameters: |
|
|---|
| Returns: |
|
|---|
map
map(mapper: Callable[[Codec], Codec]) -> PickBestCodec
Apply the mapper to all codecs that are in this combinator.
In the returned combinator, each codec is replaced by its mapped codec.
The mapper should recursively apply itself to any inner codecs that
also implement the CodecCombinatorMixin
mixin.
To automatically handle the recursive application as a caller, you can use
numcodecs_combinators.map_codec(best, mapper)
| Parameters: |
|---|
| Returns: |
|
|---|