cicada.encoding module

Functionality for encoding domain values using integer fields.

class cicada.encoding.Bits[source]

Bases: object

Converts arrays of bit values to and from field values.

decode(array, field)[source]

Convert an array of field values to bit values.

Parameters:
Returns:

decoded – Array of integers containing the values \(0\) and \(1\), or None if the input was None.

Return type:

numpy.ndarray or None

Raises:

ValueError – If array contains anything but \(0\) or \(1\).

encode(array, field)[source]

Convert an array of bit values to field values.

Parameters:
Returns:

encoded – Encoded array with the same shape as the input, containing the field values \(0\) and \(1\), or None if the input was None.

Return type:

numpy.ndarray or None

Raises:

ValueError – If array contains anything but \(0\) or \(1\).

class cicada.encoding.Boolean[source]

Bases: object

Converts arrays of boolean values to and from field values.

decode(array, field)[source]

Convert an array of field values to boolean values.

Parameters:
Returns:

decoded – Array of boolean values \(True\) and \(False\), or None if the input was None.

Return type:

numpy.ndarray or None

encode(array, field)[source]

Convert an array of boolean values to field values.

Parameters:
  • array (numpy.ndarray or None, required) – Array to convert. Nonzero values are considered \(True\), zero values are considered \(False\).

  • field (cicada.arithmetic.Field, required) – Field over which the returned values are defined.

Returns:

encoded – Encoded array with the same shape as the input, containing the field values \(0\) and \(1\), or None if the input was None.

Return type:

numpy.ndarray or None

class cicada.encoding.FixedPoint(precision=16)[source]

Bases: object

Encodes real values in a field using a fixed-point representation.

Encoded values are numpy.ndarray instances containing Python integers, with precision bits reserved for encoding fractional digits. Decoded values will be numpy.ndarray instances containining 64-bit floating point values.

Parameters:

precision (int, optional) – The number of bits reserved to store fractions in encoded values. Defaults to 16.

decode(array, field)[source]

Convert an array of field values to an array of real values.

Parameters:
Returns:

decoded – A floating point array with the same shape as the input, containing the decoded representation of array, or None if the input was None.

Return type:

numpy.ndarray

encode(array, field)[source]

Convert array of real values to an array of field values using a fixed point integer representation.

Parameters:
Returns:

encoded – Encoded array with the same shape as the input, containing the fixed precision integer representation of array, or None if the input was None.

Return type:

numpy.ndarray or None

property precision

Warning

property ‘cicada.encoding.FixedPoint.precision’ undocumented

class cicada.encoding.Identity[source]

Bases: object

Encodes and decodes field values without modification.

Encoded values are numpy.ndarray instances containing Python integers. Decoded values will be the same.

decode(array, field)[source]

Return an array of field values without modification.

Parameters:

array (numpy.ndarray, or None, required) – Array of field values created with encode().

Returns:

decoded – An array of Python integers, or None if the input was None.

Return type:

numpy.ndarray or None

encode(array, field)[source]

Convert array of integer values to an array of field values without modification.

Parameters:
Returns:

encoded – Encoded array with the same shape as the input, containing the fixed precision integer representation of array, or None if the input was None.

Return type:

numpy.ndarray or None