Skip to content

zorch.coding.linear_code

The LinearCode seam every encoding builds on.

A linear code maps a length-message_len message to a length-block_len codeword over a single field dtype (block_len > message_len; the rate is message_len / block_len). encode acts on the last axis, so leading batch axes — many polynomials, or a matrix of rows — ride through untouched. Reed-Solomon is one implementation; any other linear code (Brakedown, ...) drops in unchanged.

Implementations MUST define value-based __eq__/__hash__ over their full parameter surface, like the Permutation seam: a code seats in static jit-zone keys (inside provers/verifiers passed as static args), where identity equality silently re-traces the zone on every freshly built same-config instance (#214). A Protocol cannot enforce this — each implementation carries it (ReedSolomon, BitReversedReedSolomon).

LinearCode

Bases: Protocol

Source code in zorch/coding/linear_code.py
26
27
28
29
30
31
32
33
34
@runtime_checkable
class LinearCode(Protocol):
    message_len: int  # k, the message dimension
    block_len: int  # n, the codeword length (n > k; rate = k / n)
    dtype: Any  # field dtype of both message and codeword

    def encode(self, message: Array) -> Array:
        """Encode `(..., message_len)` to `(..., block_len)` over `dtype`."""
        ...

encode

encode(message: Array) -> Array

Encode (..., message_len) to (..., block_len) over dtype.

Source code in zorch/coding/linear_code.py
32
33
34
def encode(self, message: Array) -> Array:
    """Encode `(..., message_len)` to `(..., block_len)` over `dtype`."""
    ...