zae_engine.operation package

Submodules

zae_engine.operation.run_length module

class zae_engine.operation.run_length.Run(start_index: int, end_index: int, value: int)[source]

Bases: object

Represents a run in Run-Length Encoding (RLE).

start_index

The starting index of the run.

Type:

int

end_index

The ending index of the run.

Type:

int

value

The value of the run.

Type:

int

end_index: int
start_index: int
value: int
class zae_engine.operation.run_length.RunLengthCodec(tol_merge: int = 20, remove_incomplete: bool = False, merge_closed: bool = False, base_class: int = 0)[source]

Bases: object

A codec class for Run-Length Encoding (RLE) and decoding.

Parameters:
  • tol_merge (int, optional) – The tolerance value to merge close runs. Default is 20.

  • remove_incomplete (bool, optional) – Whether to remove incomplete runs during sanitization. Default is False.

  • merge_closed (bool, optional) – Whether to merge close runs during sanitization. Default is False.

  • base_class (int, optional) – The base class value to be excluded from runs. Default is 0.

encode(x: List[int], sense: int) RunList:[source]

Encodes a list of integers into RLE runs.

decode(encoded_runs: RunList) List[int]:[source]

Decodes RLE runs back into the original list of integers.

sanitize(run_list: RunList) RunList:[source]

Cleans and merges runs based on the codec’s parameters.

__call__(data: List[int] | List[List[int]] | RunList | List[RunList], sense: int | None = None) Union[RunList, List[RunList], List[int], List[List[int]]]:[source]

Encodes or decodes data based on the input type.

decode(encoded_runs: RunList) List[int][source]

Decode a list of RLE runs back to the original list of integers.

This method reconstructs the original sequence of integers from a RunList object. Each Run specifies the start index, end index, and the value to be filled in that range. The length of the output list is determined by the original_length stored in RunList.

Parameters:

encoded_runs (RunList) – A RunList object containing runs to be decoded.

Returns:

The decoded list of integers reconstructed from the runs.

Return type:

List[int]

encode(x: List[int], sense: int) RunList[source]

Encode a list of integers using Run-Length Encoding (RLE).

This method converts a sequence of integers into a list of runs. Each run is represented as a Run object containing the start index, end index, and the value of the run. Runs with a length smaller than the specified sense are ignored in the filtered() method.

Parameters:
  • x (List[int]) – The input list of integers to be encoded.

  • sense (int) – The minimum length of runs to be considered. Runs shorter than this value are excluded from the output when calling filtered().

Returns:

A RunList object containing all runs, the sense value, and the original list length.

Return type:

RunList

sanitize(run_list: RunList) RunList[source]

Clean and merge runs based on the codec’s parameters.

This function processes the RunList by:
  1. Removing incomplete runs (if remove_incomplete is True).

  2. Merging close runs (if merge_closed is True), while respecting the base_class.

Parameters:

run_list (RunList) – The RunList object to be sanitized.

Returns:

The sanitized RunList object.

Return type:

RunList

class zae_engine.operation.run_length.RunList(all_runs: List[Run], sense: int, original_length: int)[source]

Bases: object

Stores the results of Run-Length Encoding (RLE) and provides methods to access raw and filtered runs.

all_runs

A list of all runs without any filtering.

Type:

List[Run]

sense

The minimum length of runs to be considered in filtering.

Type:

int

original_length

The length of the original list that was encoded.

Type:

int

filtered() List[Run][source]

Returns runs that meet or exceed the specified sense value.

Returns:

A list of filtered runs.

Return type:

List[Run]

raw() List[Run][source]

Returns all runs without any filtering.

Returns:

A list of all runs.

Return type:

List[Run]

Module contents