Skip to content
Snippets Groups Projects
Commit b89f0e10 authored by Maxence Naud's avatar Maxence Naud
Browse files

[Add] type to convert Aidge::DataType to cpp type

parent c3994ab9
No related branches found
No related tags found
2 merge requests!152Update Aidge export to take a graph view has an argument instead of a...,!93Change Gather and Slice's attributes into intputs
Pipeline #42599 passed
......@@ -12,6 +12,11 @@
#ifndef AIDGE_DATA_H_
#define AIDGE_DATA_H_
#include <cstdint>
#include <fmt/format.h>
#include <string>
#include <tuple>
#include "aidge/data/half.hpp"
#include "aidge/utils/Attributes.hpp"
......@@ -64,14 +69,14 @@ template <typename T> struct NativeType { static const Aidge::DataType type; };
template <> const Aidge::DataType NativeType<double>::type = Aidge::DataType::Float64;
template <> const Aidge::DataType NativeType<float>::type = Aidge::DataType::Float32;
template <> const Aidge::DataType NativeType<half_float::half>::type = Aidge::DataType::Float16;
template <> const Aidge::DataType NativeType<int8_t>::type = Aidge::DataType::Int8;
template <> const Aidge::DataType NativeType<int16_t>::type = Aidge::DataType::Int16;
template <> const Aidge::DataType NativeType<int32_t>::type = Aidge::DataType::Int32;
template <> const Aidge::DataType NativeType<int64_t>::type = Aidge::DataType::Int64;
template <> const Aidge::DataType NativeType<uint8_t>::type = Aidge::DataType::UInt8;
template <> const Aidge::DataType NativeType<uint16_t>::type = Aidge::DataType::UInt16;
template <> const Aidge::DataType NativeType<uint32_t>::type = Aidge::DataType::UInt32;
template <> const Aidge::DataType NativeType<uint64_t>::type = Aidge::DataType::UInt64;
template <> const Aidge::DataType NativeType<std::int8_t>::type = Aidge::DataType::Int8;
template <> const Aidge::DataType NativeType<std::int16_t>::type = Aidge::DataType::Int16;
template <> const Aidge::DataType NativeType<std::int32_t>::type = Aidge::DataType::Int32;
template <> const Aidge::DataType NativeType<std::int64_t>::type = Aidge::DataType::Int64;
template <> const Aidge::DataType NativeType<std::uint8_t>::type = Aidge::DataType::UInt8;
template <> const Aidge::DataType NativeType<std::uint16_t>::type = Aidge::DataType::UInt16;
template <> const Aidge::DataType NativeType<std::uint32_t>::type = Aidge::DataType::UInt32;
template <> const Aidge::DataType NativeType<std::uint64_t>::type = Aidge::DataType::UInt64;
template <>
const char* const EnumStrings<Aidge::DataType>::data[]
......@@ -79,8 +84,26 @@ const char* const EnumStrings<Aidge::DataType>::data[]
"Int2", "Int3", "Int4", "Int5", "Int6", "Int7", "Int8", "Int16",
"Int32", "Int64", "UInt2", "UInt3", "UInt4", "UInt5", "UInt6",
"UInt7", "UInt8", "UInt16", "UInt32", "UInt64"};
template <Aidge::DataType D> struct cpptype {
using type = void; // Placeholder
};
template <> struct cpptype<Aidge::DataType::Float16> { using type = half_float::half; };
template <> struct cpptype<Aidge::DataType::Float32> { using type = float; };
template <> struct cpptype<Aidge::DataType::Float64> { using type = double; };
template <> struct cpptype<Aidge::DataType::Int8> { using type = std::int8_t; };
template <> struct cpptype<Aidge::DataType::Int16> { using type = std::int16_t; };
template <> struct cpptype<Aidge::DataType::Int32> { using type = std::int32_t; };
template <> struct cpptype<Aidge::DataType::Int64> { using type = std::int64_t; };
template <> struct cpptype<Aidge::DataType::UInt8> { using type = std::uint8_t; };
template <> struct cpptype<Aidge::DataType::UInt16> { using type = std::uint16_t; };
template <> struct cpptype<Aidge::DataType::UInt32> { using type = std::uint32_t; };
template <> struct cpptype<Aidge::DataType::UInt64> { using type = std::uint64_t; };
template <Aidge::DataType D> using cpptype_t = typename cpptype<D>::type;
}
namespace Aidge {
inline auto format_as(DataType dt) { return EnumStrings<Aidge::DataType>::data[static_cast<int>(dt)]; }
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment