numcodecs_shuffle

numcodecs_shuffle

TypedByteShuffleCodec for the numcodecs buffer compression API.

Modules:

  • typing

    Commonly used type variables.

Classes:

TypedByteShuffleCodec

Bases: Codec

Methods:

  • encode

    Shuffles the bytes in the buffer array while keeping the same shape

  • decode

    Undoes the shuffling of the bytes in the buffer array.

codec_id class-attribute instance-attribute

codec_id: str = 'shuffle.typed-byte'

encode

encode(
    buf: ndarray[S, dtype[T]],
) -> ndarray[S, dtype[T]]

Shuffles the bytes in the buffer array while keeping the same shape and data type. The shuffle size is based on the byte size of the data type. Shuffling can make typed data such as arrays of integers or floating point numbers easier to compress for a general-purpose byte-based compressor.

For instance, the big-endian 32bit integer array [0xaabbccdd, 0xaabbccdd, 0xaabbccdd, 0xaabbccdd] is shuffled to [0xaaaaaaaa, 0xbbbbbbbb, 0xcccccccc, 0xdddddddd].

Parameters:
Returns:
  • enc( ndarray[S, dtype[T]] ) –

    Shuffled array with the same shape and dtype.

decode

decode(
    buf: ndarray[S, dtype[T]],
    out: None | ndarray[S, dtype[T]] = None,
) -> ndarray[S, dtype[T]]

Undoes the shuffling of the bytes in the buffer array.

Since the shuffle size is based on the byte size of the data, the buffer and out arrays must have the same data type as the array that was originally shuffled in encode.

For instance, the big-endian 32bit integer array [0xaaaaaaaa, 0xbbbbbbbb, 0xcccccccc, 0xdddddddd] is un-shuffled back to [0xaabbccdd, 0xaabbccdd, 0xaabbccdd, 0xaabbccdd].

Parameters:
  • buf (ndarray[S, dtype[T]]) –

    Array to be un-shuffled.

  • out (None | ndarray[S, dtype[T]], default: None ) –

    Writeable array to store decoded data with the same shape and dtype.

Returns:
  • dec( ndarray[S, dtype[T]] ) –

    Un-shuffled array with the same shape and dtype.