Skip to content
Snippets Groups Projects

Low bit support for ARM Cortex-M export

Merged Thibault Allenet requested to merge low_bit_support_arm into dev
Files
17
import numpy as np
import aidge_core
from typing import Dict
datatype_converter_aide2c = {
datatype_converter_aidge2c = {
aidge_core.dtype.float64 : "double",
aidge_core.dtype.float32 : "float",
aidge_core.dtype.float16 : "half_float::half",
@@ -19,12 +20,31 @@ datatype_converter_aide2c = {
def aidge2c(datatype):
"""Convert a aidge datatype to C type
If the type is not convertible to a C type (e.g. int4), return None and raise a warning.
:param datatype: Aidge datatype to convert
:type datatype: :py:object:`aidge_core.DataType`
:return: A string representing the C type
:rtype: string
"""
if datatype in datatype_converter_aide2c:
return datatype_converter_aide2c[datatype]
if datatype in datatype_converter_aidge2c:
return datatype_converter_aidge2c[datatype]
else:
raise ValueError(f"Unsupported {datatype} aidge datatype")
def aidge2export_type(datatype: aidge_core.dtype, conversion_map: Dict[aidge_core.dtype, str] = datatype_converter_aidge2c) -> str:
"""Convert a aidge datatype to the export type specified by the map passed in argument
If the aidge type is not convertible, that is to say, is not specified in the map, a value Error is raised.
:param datatype: Aidge datatype to convert
:type datatype: :py:object:`aidge_core.DataType`
:param conversion_map: Map that specify the conversion
:type conversion_map: Dict[:py:object:`aidge_core.DataType`, str]
:return: A string representing the export type
:rtype: string
"""
if datatype in conversion_map:
return conversion_map[datatype]
else:
raise ValueError(f"Unsupported type conversion {datatype} aidge datatype for export")
Loading