identity

Identity encoder implementation for the coding experiments library.

This module provides an encoder that passes symbols through unchanged. It’s useful as a baseline for testing and as a simple passthrough when no encoding is needed.

class codinglab.encoders.identity.IdentityEncoder[source]

Bases: Encoder[SourceChar, ChannelChar], Decoder[SourceChar, ChannelChar]

Encoder that passes symbols through unchanged.

This encoder implements both Encoder and Decoder protocols, making it useful as a baseline for testing and as a simple passthrough when no actual encoding/decoding is needed.

The encoder assumes that source and channel alphabets are the same, and simply returns the input sequence unchanged.

_code_table

Always None for identity encoder

__init__()[source]

Initialize the identity encoder.

Return type:

None

encode(message)[source]

Encode a message by returning it unchanged.

This method assumes that the source symbols can be used as channel symbols (i.e., S and C are compatible types).

Parameters:

message (Sequence[TypeVar(SourceChar)]) – Sequence of source symbols to encode

Return type:

Sequence[TypeVar(ChannelChar)]

Returns:

The same sequence, unchanged

Raises:

ValueError – If the message is empty (optional validation)

decode(encoded)[source]

Decode a message by returning it unchanged.

This method assumes that the channel symbols can be used as source symbols (i.e., C and S are compatible types).

Parameters:

encoded (Sequence[TypeVar(ChannelChar)]) – Sequence of channel symbols to decode

Return type:

Sequence[TypeVar(SourceChar)]

Returns:

The same sequence, unchanged

Raises:

ValueError – If the encoded sequence is empty

property code_table: Dict[SourceChar, Sequence[ChannelChar]] | None

Get the encoding table.

The identity encoder has no code table, so this always returns None.

Returns:

None, as the identity encoder doesn’t use a code table