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:
array (
numpy.ndarray
, orNone
, required) – Array of field values containing only \(0\) or \(1\).field (
cicada.arithmetic.Field
, required) – Field over which the values in array are defined.
- Returns:
decoded – Array of integers containing the values \(0\) and \(1\), or
None
if the input wasNone
.- Return type:
- Raises:
ValueError – If array contains anything but \(0\) or \(1\).
- encode(array, field)[source]
Convert an array of bit values to field values.
- Parameters:
array (
numpy.ndarray
orNone
, required) – Array to convert containing only \(0\) or \(1\).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 wasNone
.- Return type:
- 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:
array (
numpy.ndarray
, orNone
, required) – Array of field values containing only \(0\) or \(1\).field (
cicada.arithmetic.Field
, required) – Field over which the values in array are defined.
- Returns:
decoded – Array of boolean values \(True\) and \(False\), or
None
if the input wasNone
.- Return type:
- encode(array, field)[source]
Convert an array of boolean values to field values.
- Parameters:
array (
numpy.ndarray
orNone
, 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 wasNone
.- Return type:
- 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 benumpy.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:
array (
numpy.ndarray
, orNone
, required) – Array of field values created withencode()
.field (
cicada.arithmetic.Field
, required) – Field used to create array.
- Returns:
decoded – A floating point array with the same shape as the input, containing the decoded representation of array, or
None
if the input wasNone
.- Return type:
- encode(array, field)[source]
Convert array of real values to an array of field values using a fixed point integer representation.
- Parameters:
array (
numpy.ndarray
orNone
, required) – The array to convert.field (
cicada.arithmetic.Field
, required) – The returned array elements will be members of this field.
- Returns:
encoded – Encoded array with the same shape as the input, containing the fixed precision integer representation of array, or
None
if the input wasNone
.- Return type:
- 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
, orNone
, required) – Array of field values created withencode()
.- Returns:
decoded – An array of Python integers, or
None
if the input wasNone
.- Return type:
- encode(array, field)[source]
Convert array of integer values to an array of field values without modification.
- Parameters:
array (
numpy.ndarray
orNone
, required) – The array to convert.field (
cicada.arithmetic.Field
, required) – The returned array elements will be members of this field.
- Returns:
encoded – Encoded array with the same shape as the input, containing the fixed precision integer representation of array, or
None
if the input wasNone
.- Return type: