data_specification.enums package

Module contents

class data_specification.enums.DataType

Bases: enum.Enum

Supported data types. Internally, these are actually tuples.

  1. an identifier for the enum class;
  2. the size in bytes of the type;
  3. the minimum possible value for the type;
  4. the maximum possible value for the type;
  5. the scale of the input value to convert it in integer;
  6. the pattern to use following the struct package encodings to convert the data in binary format;
  7. is whether to apply the scaling when converting to SpiNNaker’s binary format.
  8. the corresponding numpy type (or None to inhibit direct conversion via numpy, scaled conversion still supported);
  9. the text description of the type.

Note

Some types (notably 64-bit fixed-point and floating-point types) are not recommended for use on SpiNNaker due to complications with representability and lack of hardware/library support.

FLOAT_32 = 14
FLOAT_64 = 15
INT16 = 5
INT32 = 6
INT64 = 7
INT8 = 4
S015 = 21
S031 = 22
S063 = 23
S07 = 20
S1615 = 12
S3231 = 13
S87 = 11
U016 = 17
U032 = 18
U064 = 19
U08 = 16
U1616 = 9
U3232 = 10
U88 = 8
UINT16 = 1
UINT32 = 2
UINT64 = 3
UINT8 = 0
as_bytes(value)[source]

Encode the Python value as bytes with NO padding.

Parameters:value (float or int) –
Return type:bytes
check_value(value)[source]

Check the value against the allowed min and max

Raises:ValueError – If the value is outside of min to max
decode_array(values)[source]

Decodes a byte array into iterable of this type.

Parameters:values – the bytes to decode into this given data type
Return type:numpy array
decode_numpy_array(array)[source]

Decode the numpy array of SpiNNaker values according to this type.

Parameters:array (ndarray(uint32)) –
Return type:ndarray(uint32 or float64)
encode_as_int(value)[source]

Returns the value as an integer, according to this type.

Parameters:value (float or int) –
Return type:int
encode_as_numpy_int(value)[source]

Returns the value as a numpy integer, according to this type.

Note

Only works with integer and fixed point data types.

Parameters:value (float or int) –
Return type:uint32
encode_as_numpy_int_array(array)[source]

Returns the numpy array as an integer numpy array, according to this type.

Parameters:array (ndarray) –
Return type:ndarray
max

The maximum possible value for the type.

Return type:Decimal
min

The minimum possible value for the type.

Return type:Decimal
numpy_typename

The corresponding numpy type, if one exists.

scale

The scale of the input value to convert it in integer.

Return type:Decimal
size

The size in bytes of the type.

Return type:int
struct_encoding

The encoding string used for struct. Scaling may also be required.

Return type:str